myoperator-ui 0.0.60 → 0.0.61
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.js +159 -35
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12,46 +12,170 @@ import prompts from "prompts";
|
|
|
12
12
|
import ora from "ora";
|
|
13
13
|
|
|
14
14
|
// src/utils/registry.ts
|
|
15
|
+
function looksLikeTailwindClasses(str) {
|
|
16
|
+
if (!str || !str.trim()) return false;
|
|
17
|
+
const nonClassValues = [
|
|
18
|
+
"button",
|
|
19
|
+
"submit",
|
|
20
|
+
"reset",
|
|
21
|
+
"text",
|
|
22
|
+
"email",
|
|
23
|
+
"password",
|
|
24
|
+
"number",
|
|
25
|
+
"tel",
|
|
26
|
+
"url",
|
|
27
|
+
"search",
|
|
28
|
+
"checkbox",
|
|
29
|
+
"radio",
|
|
30
|
+
"file",
|
|
31
|
+
"hidden",
|
|
32
|
+
"image",
|
|
33
|
+
"color",
|
|
34
|
+
"date",
|
|
35
|
+
"time",
|
|
36
|
+
"datetime-local",
|
|
37
|
+
"default",
|
|
38
|
+
"error",
|
|
39
|
+
"warning",
|
|
40
|
+
"success",
|
|
41
|
+
"info",
|
|
42
|
+
"primary",
|
|
43
|
+
"secondary",
|
|
44
|
+
"tertiary",
|
|
45
|
+
"destructive",
|
|
46
|
+
"outline",
|
|
47
|
+
"ghost",
|
|
48
|
+
"link",
|
|
49
|
+
"dashed",
|
|
50
|
+
"solid",
|
|
51
|
+
"none",
|
|
52
|
+
"open",
|
|
53
|
+
"closed",
|
|
54
|
+
"true",
|
|
55
|
+
"false",
|
|
56
|
+
"null",
|
|
57
|
+
"undefined",
|
|
58
|
+
"single",
|
|
59
|
+
"multiple",
|
|
60
|
+
"listbox",
|
|
61
|
+
"combobox",
|
|
62
|
+
"menu",
|
|
63
|
+
"menuitem",
|
|
64
|
+
"option",
|
|
65
|
+
"switch",
|
|
66
|
+
"small",
|
|
67
|
+
"medium",
|
|
68
|
+
"large",
|
|
69
|
+
"sm",
|
|
70
|
+
"md",
|
|
71
|
+
"lg",
|
|
72
|
+
"xl",
|
|
73
|
+
"2xl",
|
|
74
|
+
"top",
|
|
75
|
+
"bottom",
|
|
76
|
+
"left",
|
|
77
|
+
"right",
|
|
78
|
+
"center",
|
|
79
|
+
"start",
|
|
80
|
+
"end",
|
|
81
|
+
"horizontal",
|
|
82
|
+
"vertical",
|
|
83
|
+
"both",
|
|
84
|
+
"auto",
|
|
85
|
+
"asc",
|
|
86
|
+
"desc",
|
|
87
|
+
"ascending",
|
|
88
|
+
"descending"
|
|
89
|
+
];
|
|
90
|
+
if (nonClassValues.includes(str.toLowerCase())) return false;
|
|
91
|
+
if (/^[A-Z][a-zA-Z]*$/.test(str)) return false;
|
|
92
|
+
if (str.startsWith("@") || str.startsWith(".") || str.startsWith("/") || str.includes("::")) return false;
|
|
93
|
+
if (/^(@[a-z0-9-]+\/)?[a-z][a-z0-9-]*$/.test(str) && !str.includes(" ")) return false;
|
|
94
|
+
const words = str.split(/\s+/);
|
|
95
|
+
return words.some((cls) => {
|
|
96
|
+
if (!cls) return false;
|
|
97
|
+
if ((cls.startsWith("aria-") || cls.startsWith("data-")) && !cls.includes("[") && !cls.includes(":")) return false;
|
|
98
|
+
const singleWordUtilities = /^(flex|grid|block|inline|contents|flow-root|hidden|invisible|visible|static|fixed|absolute|relative|sticky|isolate|isolation-auto|overflow-auto|overflow-hidden|overflow-clip|overflow-visible|overflow-scroll|overflow-x-auto|overflow-y-auto|overscroll-auto|overscroll-contain|overscroll-none|truncate|antialiased|subpixel-antialiased|italic|not-italic|underline|overline|line-through|no-underline|uppercase|lowercase|capitalize|normal-case|ordinal|slashed-zero|lining-nums|oldstyle-nums|proportional-nums|tabular-nums|diagonal-fractions|stacked-fractions|sr-only|not-sr-only|resize|resize-none|resize-x|resize-y|snap-start|snap-end|snap-center|snap-align-none|snap-normal|snap-always|touch-auto|touch-none|touch-pan-x|touch-pan-left|touch-pan-right|touch-pan-y|touch-pan-up|touch-pan-down|touch-pinch-zoom|touch-manipulation|select-none|select-text|select-all|select-auto|will-change-auto|will-change-scroll|will-change-contents|will-change-transform|grow|grow-0|shrink|shrink-0|transform|transform-cpu|transform-gpu|transform-none|transition|transition-none|transition-all|transition-colors|transition-opacity|transition-shadow|transition-transform|animate-none|animate-spin|animate-ping|animate-pulse|animate-bounce)$/;
|
|
99
|
+
if (singleWordUtilities.test(cls)) return true;
|
|
100
|
+
if (cls.includes("-")) return true;
|
|
101
|
+
if (cls.includes("[") && cls.includes("]")) return true;
|
|
102
|
+
if (cls.includes(":")) return true;
|
|
103
|
+
return false;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function prefixClassString(classString, prefix) {
|
|
107
|
+
return classString.split(" ").map((cls) => {
|
|
108
|
+
if (!cls) return cls;
|
|
109
|
+
if ((cls.startsWith("aria-") || cls.startsWith("data-")) && !cls.includes("[") && !cls.includes(":")) return cls;
|
|
110
|
+
const variantMatch = cls.match(/^([a-z][a-z0-9]*(-[a-z0-9]+)*:)+/);
|
|
111
|
+
if (variantMatch) {
|
|
112
|
+
const variants = variantMatch[0];
|
|
113
|
+
const utility = cls.slice(variants.length);
|
|
114
|
+
if (!utility) return cls;
|
|
115
|
+
if (utility.startsWith("-")) {
|
|
116
|
+
return `${variants}-${prefix}${utility.slice(1)}`;
|
|
117
|
+
}
|
|
118
|
+
return `${variants}${prefix}${utility}`;
|
|
119
|
+
}
|
|
120
|
+
if (cls.startsWith("-") && cls.length > 1) {
|
|
121
|
+
return `-${prefix}${cls.slice(1)}`;
|
|
122
|
+
}
|
|
123
|
+
if (cls.startsWith("[&")) {
|
|
124
|
+
const closeBracket = cls.indexOf("]:");
|
|
125
|
+
if (closeBracket !== -1) {
|
|
126
|
+
const selector = cls.slice(0, closeBracket + 2);
|
|
127
|
+
const utility = cls.slice(closeBracket + 2);
|
|
128
|
+
if (!utility) return cls;
|
|
129
|
+
return `${selector}${prefix}${utility}`;
|
|
130
|
+
}
|
|
131
|
+
return cls;
|
|
132
|
+
}
|
|
133
|
+
return `${prefix}${cls}`;
|
|
134
|
+
}).join(" ");
|
|
135
|
+
}
|
|
15
136
|
function prefixTailwindClasses(content, prefix) {
|
|
16
137
|
if (!prefix) return content;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return match;
|
|
138
|
+
content = content.replace(
|
|
139
|
+
/\bcva\s*\(\s*"([^"]*)"/g,
|
|
140
|
+
(match, baseClasses) => {
|
|
141
|
+
if (!looksLikeTailwindClasses(baseClasses)) return match;
|
|
142
|
+
const prefixed = prefixClassString(baseClasses, prefix);
|
|
143
|
+
return match.replace(`"${baseClasses}"`, `"${prefixed}"`);
|
|
21
144
|
}
|
|
22
|
-
|
|
23
|
-
|
|
145
|
+
);
|
|
146
|
+
content = content.replace(
|
|
147
|
+
/\bcn\s*\(([^)]+)\)/g,
|
|
148
|
+
(match, args) => {
|
|
149
|
+
const prefixedArgs = args.replace(
|
|
150
|
+
/"([^"]*)"/g,
|
|
151
|
+
(m, classes) => {
|
|
152
|
+
if (!looksLikeTailwindClasses(classes)) return m;
|
|
153
|
+
const prefixed = prefixClassString(classes, prefix);
|
|
154
|
+
return `"${prefixed}"`;
|
|
155
|
+
}
|
|
156
|
+
);
|
|
157
|
+
return `cn(${prefixedArgs})`;
|
|
24
158
|
}
|
|
25
|
-
|
|
26
|
-
|
|
159
|
+
);
|
|
160
|
+
content = content.replace(
|
|
161
|
+
/className\s*=\s*"([^"]*)"/g,
|
|
162
|
+
(match, classes) => {
|
|
163
|
+
if (!looksLikeTailwindClasses(classes)) return match;
|
|
164
|
+
const prefixed = prefixClassString(classes, prefix);
|
|
165
|
+
return `className="${prefixed}"`;
|
|
27
166
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return `-${cleanPrefix}${cls.slice(1)}`;
|
|
41
|
-
}
|
|
42
|
-
if (cls.startsWith("[&")) {
|
|
43
|
-
const closeBracket = cls.indexOf("]:");
|
|
44
|
-
if (closeBracket !== -1) {
|
|
45
|
-
const selector = cls.slice(0, closeBracket + 2);
|
|
46
|
-
const utility = cls.slice(closeBracket + 2);
|
|
47
|
-
return `${selector}${cleanPrefix}${utility}`;
|
|
48
|
-
}
|
|
49
|
-
return cls;
|
|
50
|
-
}
|
|
51
|
-
return `${cleanPrefix}${cls}`;
|
|
52
|
-
}).join(" ");
|
|
53
|
-
return `"${prefixedClasses}"`;
|
|
54
|
-
});
|
|
167
|
+
);
|
|
168
|
+
content = content.replace(
|
|
169
|
+
/(\w+):\s*"([^"]+)"/g,
|
|
170
|
+
(match, key, value) => {
|
|
171
|
+
const nonClassKeys = ["name", "description", "displayName", "type", "role", "id", "htmlFor", "for", "placeholder", "title", "alt", "src", "href", "target", "rel", "method", "action", "enctype", "accept", "pattern", "autocomplete", "value", "defaultValue", "label", "text", "message", "error", "helperText", "ariaLabel", "ariaDescribedBy"];
|
|
172
|
+
if (nonClassKeys.includes(key)) return match;
|
|
173
|
+
if (!looksLikeTailwindClasses(value)) return match;
|
|
174
|
+
const prefixed = prefixClassString(value, prefix);
|
|
175
|
+
return `${key}: "${prefixed}"`;
|
|
176
|
+
}
|
|
177
|
+
);
|
|
178
|
+
return content;
|
|
55
179
|
}
|
|
56
180
|
async function getRegistry(prefix = "") {
|
|
57
181
|
return {
|