clava 0.6.0 → 0.6.2
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/CHANGELOG.md +15 -0
- package/README.md +24 -16
- package/dist/index.d.ts +31 -25
- package/dist/index.js +384 -594
- package/dist/index.js.map +1 -1
- package/package.json +18 -3
- package/src/index.ts +281 -634
- package/src/refine-warning.ts +4 -11
- package/src/types.ts +27 -16
- package/src/utils.ts +123 -99
- package/rolldown.config.ts +0 -15
- package/tests/_utils.ts +0 -178
- package/tests/build.test.ts +0 -93
- package/tests/class-style.test.ts +0 -341
- package/tests/component-api.test.ts +0 -548
- package/tests/extend.test.ts +0 -421
- package/tests/function-variants.test.ts +0 -378
- package/tests/language-service.test.ts +0 -192
- package/tests/prototype-pollution.test.ts +0 -46
- package/tests/react.test.ts +0 -40
- package/tests/refine-warning.test.ts +0 -28
- package/tests/refine.test.ts +0 -1498
- package/tests/solid.test.ts +0 -64
- package/tests/split-props.test.ts +0 -662
- package/tests/variants-inference.test.ts +0 -401
- package/tests/variants.test.ts +0 -408
- package/tsconfig.json +0 -7
package/dist/index.js
CHANGED
|
@@ -1,106 +1,68 @@
|
|
|
1
1
|
import clsx from "clsx";
|
|
2
|
-
//#region src/refine-warning.ts
|
|
3
|
-
function captureCreationFrame(skipFn) {
|
|
4
|
-
if (process.env.NODE_ENV === "production") return void 0;
|
|
5
|
-
if (typeof Error.captureStackTrace === "function") {
|
|
6
|
-
const holder = {};
|
|
7
|
-
Error.captureStackTrace(holder, skipFn);
|
|
8
|
-
return holder;
|
|
9
|
-
}
|
|
10
|
-
return /* @__PURE__ */ new Error();
|
|
11
|
-
}
|
|
12
|
-
function formatCreationStack(frame) {
|
|
13
|
-
let stack = frame.stack;
|
|
14
|
-
if (!stack) return void 0;
|
|
15
|
-
const newlineIdx = stack.indexOf("\n");
|
|
16
|
-
if (newlineIdx > 0) {
|
|
17
|
-
const firstLine = stack.slice(0, newlineIdx);
|
|
18
|
-
if (firstLine === "Error" || firstLine.startsWith("Error:")) stack = stack.slice(newlineIdx + 1);
|
|
19
|
-
}
|
|
20
|
-
const frames = stack.split("\n");
|
|
21
|
-
for (let i = 0; i < frames.length; i++) {
|
|
22
|
-
const line = frames[i]?.trim();
|
|
23
|
-
if (!line) continue;
|
|
24
|
-
if (isInternalCreationFrame(line)) continue;
|
|
25
|
-
if (line.includes("/node_modules/")) continue;
|
|
26
|
-
if (line.includes("\\node_modules\\")) continue;
|
|
27
|
-
if (line.includes("node:internal")) continue;
|
|
28
|
-
return ` ${line}`;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function isInternalCreationFrame(line) {
|
|
32
|
-
if (line.includes("captureCreationFrame")) return true;
|
|
33
|
-
if (line.startsWith("at cv ")) return true;
|
|
34
|
-
if (line.startsWith("at cv(")) return true;
|
|
35
|
-
if (line.startsWith("cv@")) return true;
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
function formatVariantValue(value) {
|
|
39
|
-
if (typeof value === "string") return JSON.stringify(value);
|
|
40
|
-
if (typeof value === "number") {
|
|
41
|
-
if (Number.isNaN(value)) return "NaN";
|
|
42
|
-
return String(value);
|
|
43
|
-
}
|
|
44
|
-
if (typeof value === "bigint") return `${value}n`;
|
|
45
|
-
if (value === void 0) return "undefined";
|
|
46
|
-
if (value === null) return "null";
|
|
47
|
-
if (typeof value === "boolean") return String(value);
|
|
48
|
-
if (typeof value === "symbol") return String(value);
|
|
49
|
-
if (typeof value === "function") return "[function]";
|
|
50
|
-
return "[object]";
|
|
51
|
-
}
|
|
52
|
-
function setVariantChange(into, key, from, to) {
|
|
53
|
-
into.set(key, {
|
|
54
|
-
from,
|
|
55
|
-
to
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
function accumulateUnstableVariantChanges(into, prev, next) {
|
|
59
|
-
for (const key in next) {
|
|
60
|
-
if (!Object.hasOwn(next, key)) continue;
|
|
61
|
-
if (!Object.is(prev[key], next[key])) setVariantChange(into, key, prev[key], next[key]);
|
|
62
|
-
}
|
|
63
|
-
for (const key in prev) {
|
|
64
|
-
if (!Object.hasOwn(prev, key)) continue;
|
|
65
|
-
if (Object.hasOwn(next, key)) continue;
|
|
66
|
-
setVariantChange(into, key, prev[key], void 0);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
function formatVariantChanges(changes) {
|
|
70
|
-
return Array.from(changes).map(([key, { from, to }]) => {
|
|
71
|
-
return `${key}: ${formatVariantValue(from)} -> ${formatVariantValue(to)}`;
|
|
72
|
-
}).join(", ");
|
|
73
|
-
}
|
|
74
|
-
function warnRefineLimit({ runState, creationFrame, unstableChanges }) {
|
|
75
|
-
if (process.env.NODE_ENV === "production") return;
|
|
76
|
-
if (runState.warned) return;
|
|
77
|
-
runState.warned = true;
|
|
78
|
-
let message = "Clava: Maximum refine iterations exceeded. This can happen when a computed default variant or refine callback changes one of the variants on every run.";
|
|
79
|
-
if (unstableChanges && unstableChanges.size > 0) {
|
|
80
|
-
message += `\nVariant(s) that did not stabilize: ${Array.from(unstableChanges.keys()).join(", ")}.`;
|
|
81
|
-
message += `\nLatest variant changes before warning: ${formatVariantChanges(unstableChanges)}.`;
|
|
82
|
-
}
|
|
83
|
-
if (creationFrame) {
|
|
84
|
-
const creationStack = formatCreationStack(creationFrame);
|
|
85
|
-
if (creationStack) message += `\nComponent created at:\n${creationStack}`;
|
|
86
|
-
}
|
|
87
|
-
console.warn(message);
|
|
88
|
-
}
|
|
89
|
-
//#endregion
|
|
90
2
|
//#region src/utils.ts
|
|
91
|
-
const hasOwn = Object.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
3
|
+
const hasOwn = Object.hasOwn;
|
|
4
|
+
const unitlessNumberProperties = /* @__PURE__ */ new Set([
|
|
5
|
+
"animationIterationCount",
|
|
6
|
+
"aspectRatio",
|
|
7
|
+
"borderImage",
|
|
8
|
+
"borderImageOutset",
|
|
9
|
+
"borderImageSlice",
|
|
10
|
+
"borderImageWidth",
|
|
11
|
+
"boxFlex",
|
|
12
|
+
"boxFlexGroup",
|
|
13
|
+
"boxOrdinalGroup",
|
|
14
|
+
"columnCount",
|
|
15
|
+
"columns",
|
|
16
|
+
"fillOpacity",
|
|
17
|
+
"flex",
|
|
18
|
+
"flexGrow",
|
|
19
|
+
"flexNegative",
|
|
20
|
+
"flexOrder",
|
|
21
|
+
"flexPositive",
|
|
22
|
+
"flexShrink",
|
|
23
|
+
"floodOpacity",
|
|
24
|
+
"fontSizeAdjust",
|
|
25
|
+
"fontWeight",
|
|
26
|
+
"gridArea",
|
|
27
|
+
"gridColumn",
|
|
28
|
+
"gridColumnEnd",
|
|
29
|
+
"gridColumnSpan",
|
|
30
|
+
"gridColumnStart",
|
|
31
|
+
"gridRow",
|
|
32
|
+
"gridRowEnd",
|
|
33
|
+
"gridRowSpan",
|
|
34
|
+
"gridRowStart",
|
|
35
|
+
"hyphenateLimitChars",
|
|
36
|
+
"initialLetter",
|
|
37
|
+
"lineClamp",
|
|
38
|
+
"lineHeight",
|
|
39
|
+
"maskBorder",
|
|
40
|
+
"maskBorderOutset",
|
|
41
|
+
"maskBorderSlice",
|
|
42
|
+
"maskBorderWidth",
|
|
43
|
+
"mathDepth",
|
|
44
|
+
"maxLines",
|
|
45
|
+
"opacity",
|
|
46
|
+
"order",
|
|
47
|
+
"orphans",
|
|
48
|
+
"scale",
|
|
49
|
+
"shapeImageThreshold",
|
|
50
|
+
"stopOpacity",
|
|
51
|
+
"strokeDasharray",
|
|
52
|
+
"strokeDashoffset",
|
|
53
|
+
"strokeMiterlimit",
|
|
54
|
+
"strokeOpacity",
|
|
55
|
+
"strokeWidth",
|
|
56
|
+
"tabSize",
|
|
57
|
+
"widows",
|
|
58
|
+
"zIndex",
|
|
59
|
+
"zoom"
|
|
60
|
+
]);
|
|
61
|
+
function isCustomProperty(property) {
|
|
62
|
+
return property.charCodeAt(0) === 45 && property.charCodeAt(1) === 45;
|
|
95
63
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Converts a hyphenated CSS property name to camelCase.
|
|
98
|
-
* @example
|
|
99
|
-
* hyphenToCamel("background-color") // "backgroundColor"
|
|
100
|
-
* hyphenToCamel("--custom-var") // "--custom-var" (CSS variables are preserved)
|
|
101
|
-
*/
|
|
102
64
|
function hyphenToCamel(str) {
|
|
103
|
-
if (
|
|
65
|
+
if (isCustomProperty(str)) return str;
|
|
104
66
|
let hyphenIndex = str.indexOf("-");
|
|
105
67
|
if (hyphenIndex === -1) return str;
|
|
106
68
|
let result = "";
|
|
@@ -113,8 +75,10 @@ function hyphenToCamel(str) {
|
|
|
113
75
|
lastIndex = nextIndex;
|
|
114
76
|
break;
|
|
115
77
|
}
|
|
116
|
-
|
|
117
|
-
|
|
78
|
+
const code = str.charCodeAt(nextIndex);
|
|
79
|
+
if (code >= 65 && code <= 90 || code >= 97 && code <= 122) {
|
|
80
|
+
const isMicrosoftPrefix = hyphenIndex === 0 && str.startsWith("ms-", 1);
|
|
81
|
+
result += isMicrosoftPrefix ? str[nextIndex] : str[nextIndex].toUpperCase();
|
|
118
82
|
lastIndex = nextIndex + 1;
|
|
119
83
|
} else {
|
|
120
84
|
result += "-";
|
|
@@ -124,19 +88,14 @@ function hyphenToCamel(str) {
|
|
|
124
88
|
}
|
|
125
89
|
return result + str.slice(lastIndex);
|
|
126
90
|
}
|
|
127
|
-
/**
|
|
128
|
-
* Converts a camelCase CSS property name to hyphenated form.
|
|
129
|
-
* @example
|
|
130
|
-
* camelToHyphen("backgroundColor") // "background-color"
|
|
131
|
-
* camelToHyphen("--customVar") // "--customVar" (CSS variables are preserved)
|
|
132
|
-
*/
|
|
133
91
|
function camelToHyphen(str) {
|
|
134
|
-
if (
|
|
92
|
+
if (isCustomProperty(str)) return str;
|
|
135
93
|
let result = "";
|
|
136
94
|
let lastIndex = 0;
|
|
137
95
|
for (let i = 0; i < str.length; i++) {
|
|
138
96
|
const code = str.charCodeAt(i);
|
|
139
97
|
if (code < 65 || code > 90) continue;
|
|
98
|
+
if (i === 2 && str.startsWith("ms")) result += "-";
|
|
140
99
|
result += str.slice(lastIndex, i);
|
|
141
100
|
result += "-";
|
|
142
101
|
result += str[i].toLowerCase();
|
|
@@ -145,25 +104,36 @@ function camelToHyphen(str) {
|
|
|
145
104
|
if (lastIndex === 0) return str;
|
|
146
105
|
return result + str.slice(lastIndex);
|
|
147
106
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
107
|
+
function hasVendorPrefix(property, prefix) {
|
|
108
|
+
const nextCode = property.charCodeAt(prefix.length);
|
|
109
|
+
if (nextCode < 65 || nextCode > 90) return false;
|
|
110
|
+
return property.startsWith(prefix);
|
|
111
|
+
}
|
|
112
|
+
const vendorPrefixes = [
|
|
113
|
+
"Webkit",
|
|
114
|
+
"Moz",
|
|
115
|
+
"ms",
|
|
116
|
+
"Ms",
|
|
117
|
+
"O"
|
|
118
|
+
];
|
|
119
|
+
function isUnitlessNumberProperty(property) {
|
|
120
|
+
if (unitlessNumberProperties.has(property)) return true;
|
|
121
|
+
for (const prefix of vendorPrefixes) {
|
|
122
|
+
if (!hasVendorPrefix(property, prefix)) continue;
|
|
123
|
+
const firstCode = property.charCodeAt(prefix.length);
|
|
124
|
+
const unprefixedProperty = String.fromCharCode(firstCode + 32) + property.slice(prefix.length + 1);
|
|
125
|
+
return unitlessNumberProperties.has(unprefixedProperty);
|
|
126
|
+
}
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
function normalizeStyleValue(property, value) {
|
|
155
130
|
if (typeof value === "string") return value;
|
|
131
|
+
if (isCustomProperty(property)) return value;
|
|
132
|
+
if (isUnitlessNumberProperty(property)) return value;
|
|
156
133
|
return `${value}px`;
|
|
157
134
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
* @example
|
|
161
|
-
* htmlStyleToStyleValue("background-color: red; font-size: 16px;");
|
|
162
|
-
* // { backgroundColor: "red", fontSize: "16px" }
|
|
163
|
-
*/
|
|
164
|
-
function htmlStyleToStyleValue(styleString) {
|
|
165
|
-
if (!styleString) return {};
|
|
166
|
-
const result = {};
|
|
135
|
+
function htmlStyleToStyleValue(styleString, result = {}) {
|
|
136
|
+
if (!styleString) return result;
|
|
167
137
|
const len = styleString.length;
|
|
168
138
|
let i = 0;
|
|
169
139
|
while (i < len) {
|
|
@@ -216,48 +186,20 @@ function htmlStyleToStyleValue(styleString) {
|
|
|
216
186
|
}
|
|
217
187
|
return result;
|
|
218
188
|
}
|
|
219
|
-
|
|
220
|
-
* Converts a hyphenated style object to a camelCase StyleValue object.
|
|
221
|
-
* @example
|
|
222
|
-
* htmlObjStyleToStyleValue({ "background-color": "red", "font-size": "16px" });
|
|
223
|
-
* // { backgroundColor: "red", fontSize: "16px" }
|
|
224
|
-
*/
|
|
225
|
-
function htmlObjStyleToStyleValue(style) {
|
|
226
|
-
const result = {};
|
|
189
|
+
function htmlObjStyleToStyleValue(style, result = {}) {
|
|
227
190
|
for (const key in style) {
|
|
228
|
-
if (!hasOwn
|
|
191
|
+
if (!hasOwn(style, key)) continue;
|
|
229
192
|
const value = style[key];
|
|
230
193
|
if (value == null) continue;
|
|
231
|
-
|
|
194
|
+
const property = hyphenToCamel(key);
|
|
195
|
+
result[property] = normalizeStyleValue(property, value);
|
|
232
196
|
}
|
|
233
197
|
return result;
|
|
234
198
|
}
|
|
235
|
-
/**
|
|
236
|
-
* Converts a camelCase style object to a StyleValue object.
|
|
237
|
-
* @example
|
|
238
|
-
* jsxStyleToStyleValue({ backgroundColor: "red", fontSize: 16 });
|
|
239
|
-
* // { backgroundColor: "red", fontSize: "16px" }
|
|
240
|
-
*/
|
|
241
|
-
function jsxStyleToStyleValue(style) {
|
|
242
|
-
const result = {};
|
|
243
|
-
for (const key in style) {
|
|
244
|
-
if (!hasOwn.call(style, key)) continue;
|
|
245
|
-
const value = style[key];
|
|
246
|
-
if (value == null) continue;
|
|
247
|
-
result[key] = parseLengthValue(value);
|
|
248
|
-
}
|
|
249
|
-
return result;
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Converts a StyleValue object to a CSS style string.
|
|
253
|
-
* @example
|
|
254
|
-
* styleValueToHTMLStyle({ backgroundColor: "red", fontSize: "16px" });
|
|
255
|
-
* // "background-color: red; font-size: 16px;"
|
|
256
|
-
*/
|
|
257
199
|
function styleValueToHTMLStyle(style) {
|
|
258
200
|
let result = "";
|
|
259
201
|
for (const key in style) {
|
|
260
|
-
if (!hasOwn
|
|
202
|
+
if (!hasOwn(style, key)) continue;
|
|
261
203
|
const value = style[key];
|
|
262
204
|
if (value == null) continue;
|
|
263
205
|
if (result) result += "; ";
|
|
@@ -268,110 +210,124 @@ function styleValueToHTMLStyle(style) {
|
|
|
268
210
|
if (!result) return "";
|
|
269
211
|
return `${result};`;
|
|
270
212
|
}
|
|
271
|
-
/**
|
|
272
|
-
* Converts a StyleValue object to a hyphenated style object.
|
|
273
|
-
* @example
|
|
274
|
-
* styleValueToHTMLObjStyle({ backgroundColor: "red", fontSize: "16px" });
|
|
275
|
-
* // { "background-color": "red", "font-size": "16px" }
|
|
276
|
-
*/
|
|
277
213
|
function styleValueToHTMLObjStyle(style) {
|
|
278
214
|
const result = {};
|
|
279
215
|
for (const key in style) {
|
|
280
|
-
if (!hasOwn
|
|
216
|
+
if (!hasOwn(style, key)) continue;
|
|
281
217
|
const value = style[key];
|
|
282
218
|
if (value == null) continue;
|
|
283
219
|
result[camelToHyphen(key)] = value;
|
|
284
220
|
}
|
|
285
221
|
return result;
|
|
286
222
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region src/refine-warning.ts
|
|
225
|
+
function captureCreationFrame(skipFn) {
|
|
226
|
+
if (process.env.NODE_ENV === "production") return void 0;
|
|
227
|
+
if (typeof Error.captureStackTrace === "function") {
|
|
228
|
+
const holder = {};
|
|
229
|
+
Error.captureStackTrace(holder, skipFn);
|
|
230
|
+
return holder;
|
|
231
|
+
}
|
|
232
|
+
return /* @__PURE__ */ new Error();
|
|
295
233
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
234
|
+
function formatCreationStack(frame) {
|
|
235
|
+
let stack = frame.stack;
|
|
236
|
+
if (!stack) return void 0;
|
|
237
|
+
const newlineIdx = stack.indexOf("\n");
|
|
238
|
+
if (newlineIdx > 0) {
|
|
239
|
+
const firstLine = stack.slice(0, newlineIdx);
|
|
240
|
+
if (firstLine === "Error" || firstLine.startsWith("Error:")) stack = stack.slice(newlineIdx + 1);
|
|
241
|
+
}
|
|
242
|
+
const frames = stack.split("\n");
|
|
243
|
+
for (let i = 0; i < frames.length; i++) {
|
|
244
|
+
const line = frames[i]?.trim();
|
|
245
|
+
if (!line) continue;
|
|
246
|
+
if (isInternalCreationFrame(line)) continue;
|
|
247
|
+
if (line.includes("/node_modules/")) continue;
|
|
248
|
+
if (line.includes("\\node_modules\\")) continue;
|
|
249
|
+
if (line.includes("node:internal")) continue;
|
|
250
|
+
return ` ${line}`;
|
|
307
251
|
}
|
|
252
|
+
}
|
|
253
|
+
function isInternalCreationFrame(line) {
|
|
254
|
+
if (line.includes("captureCreationFrame")) return true;
|
|
255
|
+
if (line.startsWith("at cv ")) return true;
|
|
256
|
+
if (line.startsWith("at cv(")) return true;
|
|
257
|
+
if (line.startsWith("cv@")) return true;
|
|
308
258
|
return false;
|
|
309
259
|
}
|
|
260
|
+
function formatVariantValue(value) {
|
|
261
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
262
|
+
if (typeof value === "number") {
|
|
263
|
+
if (Number.isNaN(value)) return "NaN";
|
|
264
|
+
return String(value);
|
|
265
|
+
}
|
|
266
|
+
if (typeof value === "bigint") return `${value}n`;
|
|
267
|
+
if (value === void 0) return "undefined";
|
|
268
|
+
if (value === null) return "null";
|
|
269
|
+
if (typeof value === "boolean") return String(value);
|
|
270
|
+
if (typeof value === "symbol") return String(value);
|
|
271
|
+
if (typeof value === "function") return "[function]";
|
|
272
|
+
return "[object]";
|
|
273
|
+
}
|
|
274
|
+
function setVariantChange(into, key, from, to) {
|
|
275
|
+
into.set(key, {
|
|
276
|
+
from,
|
|
277
|
+
to
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
function accumulateUnstableVariantChanges(into, prev, next) {
|
|
281
|
+
for (const key in next) {
|
|
282
|
+
if (!hasOwn(next, key)) continue;
|
|
283
|
+
if (!Object.is(prev[key], next[key])) setVariantChange(into, key, prev[key], next[key]);
|
|
284
|
+
}
|
|
285
|
+
for (const key in prev) {
|
|
286
|
+
if (!hasOwn(prev, key)) continue;
|
|
287
|
+
if (hasOwn(next, key)) continue;
|
|
288
|
+
setVariantChange(into, key, prev[key], void 0);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function formatVariantChanges(changes) {
|
|
292
|
+
return Array.from(changes).map(([key, { from, to }]) => {
|
|
293
|
+
return `${key}: ${formatVariantValue(from)} -> ${formatVariantValue(to)}`;
|
|
294
|
+
}).join(", ");
|
|
295
|
+
}
|
|
296
|
+
function warnRefineLimit({ creationFrame, unstableChanges }) {
|
|
297
|
+
if (process.env.NODE_ENV === "production") return;
|
|
298
|
+
let message = "Clava: Maximum refine iterations exceeded. This can happen when a computed default variant or refine callback changes one of the variants on every run.";
|
|
299
|
+
if (unstableChanges && unstableChanges.size > 0) {
|
|
300
|
+
message += `\nVariant(s) that did not stabilize: ${Array.from(unstableChanges.keys()).join(", ")}.`;
|
|
301
|
+
message += `\nLatest variant changes before warning: ${formatVariantChanges(unstableChanges)}.`;
|
|
302
|
+
}
|
|
303
|
+
if (creationFrame) {
|
|
304
|
+
const creationStack = formatCreationStack(creationFrame);
|
|
305
|
+
if (creationStack) message += `\nComponent created at:\n${creationStack}`;
|
|
306
|
+
}
|
|
307
|
+
console.warn(message);
|
|
308
|
+
}
|
|
310
309
|
//#endregion
|
|
311
310
|
//#region src/index.ts
|
|
312
311
|
const META_KEY = "__meta";
|
|
313
|
-
const EMPTY_DEFAULTS =
|
|
312
|
+
const EMPTY_DEFAULTS = {};
|
|
314
313
|
const MAX_REFINE_RUNS = 50;
|
|
315
314
|
function areVariantsEqual(a, b) {
|
|
316
315
|
for (const key in a) {
|
|
317
|
-
if (!
|
|
316
|
+
if (!hasOwn(a, key)) continue;
|
|
318
317
|
if (!Object.is(a[key], b[key])) return false;
|
|
319
318
|
}
|
|
320
319
|
for (const key in b) {
|
|
321
|
-
if (!
|
|
322
|
-
if (!
|
|
320
|
+
if (!hasOwn(b, key)) continue;
|
|
321
|
+
if (!hasOwn(a, key)) return false;
|
|
323
322
|
}
|
|
324
323
|
return true;
|
|
325
324
|
}
|
|
326
|
-
function getExtUserVariantProps(userVariantProps, protectedVariants
|
|
327
|
-
|
|
328
|
-
Object.assign(extUserVariantProps, userVariantProps);
|
|
329
|
-
if (protectedVariants) Object.assign(extUserVariantProps, protectedVariants);
|
|
330
|
-
if (changedVariants) Object.assign(extUserVariantProps, changedVariants);
|
|
331
|
-
return extUserVariantProps;
|
|
332
|
-
}
|
|
333
|
-
function mergeVariants(target, source, skipKeys) {
|
|
334
|
-
let changed = false;
|
|
335
|
-
if (!skipKeys || skipKeys.size === 0) {
|
|
336
|
-
for (const key in source) {
|
|
337
|
-
if (!Object.hasOwn(source, key)) continue;
|
|
338
|
-
const value = source[key];
|
|
339
|
-
if (!Object.is(target[key], value)) changed = true;
|
|
340
|
-
target[key] = value;
|
|
341
|
-
}
|
|
342
|
-
return changed;
|
|
343
|
-
}
|
|
344
|
-
for (const key in source) {
|
|
345
|
-
if (!Object.hasOwn(source, key)) continue;
|
|
346
|
-
if (skipKeys.has(key)) continue;
|
|
347
|
-
const value = source[key];
|
|
348
|
-
if (!Object.is(target[key], value)) changed = true;
|
|
349
|
-
target[key] = value;
|
|
350
|
-
}
|
|
351
|
-
return changed;
|
|
352
|
-
}
|
|
353
|
-
function mergeProtectedIntoBase(baseResolved, protectedVariants) {
|
|
354
|
-
if (!protectedVariants) return baseResolved;
|
|
355
|
-
let hasProtected = false;
|
|
356
|
-
for (const key in protectedVariants) {
|
|
357
|
-
if (!Object.hasOwn(protectedVariants, key)) continue;
|
|
358
|
-
hasProtected = true;
|
|
359
|
-
break;
|
|
360
|
-
}
|
|
361
|
-
if (!hasProtected) return baseResolved;
|
|
362
|
-
const resolved = {};
|
|
363
|
-
Object.assign(resolved, baseResolved);
|
|
364
|
-
for (const key in protectedVariants) {
|
|
365
|
-
if (!Object.hasOwn(protectedVariants, key)) continue;
|
|
366
|
-
resolved[key] = protectedVariants[key];
|
|
367
|
-
}
|
|
368
|
-
return resolved;
|
|
325
|
+
function getExtUserVariantProps(userVariantProps, protectedVariants) {
|
|
326
|
+
return Object.assign({}, userVariantProps, protectedVariants);
|
|
369
327
|
}
|
|
370
|
-
function
|
|
371
|
-
return
|
|
372
|
-
}
|
|
373
|
-
function setComponentMeta(component, meta) {
|
|
374
|
-
component[META_KEY] = meta;
|
|
328
|
+
function mergeProtectedIntoBase(baseResolved, protectedVariants, protectedVariantKeys) {
|
|
329
|
+
if (protectedVariantKeys.size === 0) return baseResolved;
|
|
330
|
+
return Object.assign({}, baseResolved, protectedVariants);
|
|
375
331
|
}
|
|
376
332
|
function isRecordObject(value) {
|
|
377
333
|
if (typeof value !== "object") return false;
|
|
@@ -379,126 +335,41 @@ function isRecordObject(value) {
|
|
|
379
335
|
if (Array.isArray(value)) return false;
|
|
380
336
|
return true;
|
|
381
337
|
}
|
|
382
|
-
/**
|
|
383
|
-
* Checks if a value is a style-class object (`{ style, class? }`).
|
|
384
|
-
*/
|
|
385
|
-
function isStyleClassValue(value) {
|
|
386
|
-
if (!isRecordObject(value)) return false;
|
|
387
|
-
return "style" in value || "class" in value;
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* Converts any style input (string, JSX object, or HTML object) to a normalized
|
|
391
|
-
* StyleValue.
|
|
392
|
-
*/
|
|
393
338
|
function normalizeStyle(style) {
|
|
394
339
|
if (typeof style === "string") return htmlStyleToStyleValue(style);
|
|
395
|
-
if (typeof style === "object" && style != null)
|
|
396
|
-
if (isHTMLObjStyle(style)) return htmlObjStyleToStyleValue(style);
|
|
397
|
-
return jsxStyleToStyleValue(style);
|
|
398
|
-
}
|
|
340
|
+
if (typeof style === "object" && style != null) return htmlObjStyleToStyleValue(style);
|
|
399
341
|
return {};
|
|
400
342
|
}
|
|
401
|
-
function extractStyleClassPrebuilt(value) {
|
|
402
|
-
const styleNorm = normalizeStyle(value.style);
|
|
403
|
-
return {
|
|
404
|
-
class: value.class ?? null,
|
|
405
|
-
style: styleNorm && Object.keys(styleNorm).length > 0 ? styleNorm : null
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
343
|
function extractClassAndStylePrebuilt(value) {
|
|
409
|
-
if (
|
|
410
|
-
|
|
344
|
+
if (!isRecordObject(value)) return {
|
|
345
|
+
class: value,
|
|
346
|
+
style: null
|
|
347
|
+
};
|
|
348
|
+
if (!("style" in value || "class" in value)) return {
|
|
411
349
|
class: null,
|
|
412
350
|
style: null
|
|
413
351
|
};
|
|
352
|
+
const styleClassValue = value;
|
|
353
|
+
const style = normalizeStyle(styleClassValue.style);
|
|
414
354
|
return {
|
|
415
|
-
class:
|
|
416
|
-
style: null
|
|
355
|
+
class: styleClassValue.class ?? null,
|
|
356
|
+
style: Object.keys(style).length > 0 ? style : null
|
|
417
357
|
};
|
|
418
358
|
}
|
|
419
|
-
/**
|
|
420
|
-
* Gets all variant keys from a component's config, including extended
|
|
421
|
-
* components.
|
|
422
|
-
*/
|
|
423
|
-
function collectVariantKeys(config) {
|
|
424
|
-
const keys = /* @__PURE__ */ new Set();
|
|
425
|
-
if (config.extend) for (const ext of config.extend) {
|
|
426
|
-
const extKeys = ext.variantKeys;
|
|
427
|
-
for (let i = 0; i < extKeys.length; i++) keys.add(extKeys[i]);
|
|
428
|
-
}
|
|
429
|
-
if (config.variants) for (const key in config.variants) {
|
|
430
|
-
if (!Object.hasOwn(config.variants, key)) continue;
|
|
431
|
-
if (config.variants[key] === null) {
|
|
432
|
-
keys.delete(key);
|
|
433
|
-
continue;
|
|
434
|
-
}
|
|
435
|
-
keys.add(key);
|
|
436
|
-
}
|
|
437
|
-
return Array.from(keys);
|
|
438
|
-
}
|
|
439
359
|
function getVariantValueKey(value) {
|
|
440
360
|
if (typeof value === "string") return value;
|
|
441
361
|
if (typeof value === "number") return String(value);
|
|
442
362
|
if (typeof value === "boolean") return String(value);
|
|
443
363
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
if (!
|
|
447
|
-
|
|
448
|
-
if (!Object.hasOwn(config.variants, key)) continue;
|
|
449
|
-
if (config.variants[key] === null) keys.add(key);
|
|
450
|
-
}
|
|
451
|
-
return keys;
|
|
452
|
-
}
|
|
453
|
-
function collectDisabledVariantValues(config) {
|
|
454
|
-
const values = {};
|
|
455
|
-
if (!config.variants) return values;
|
|
456
|
-
for (const key in config.variants) {
|
|
457
|
-
if (!Object.hasOwn(config.variants, key)) continue;
|
|
458
|
-
const variant = config.variants[key];
|
|
459
|
-
if (!isRecordObject(variant)) continue;
|
|
460
|
-
let bucket;
|
|
461
|
-
for (const variantValue in variant) {
|
|
462
|
-
if (!Object.hasOwn(variant, variantValue)) continue;
|
|
463
|
-
if (variant[variantValue] !== null) continue;
|
|
464
|
-
if (!bucket) {
|
|
465
|
-
bucket = /* @__PURE__ */ new Set();
|
|
466
|
-
values[key] = bucket;
|
|
467
|
-
}
|
|
468
|
-
bucket.add(variantValue);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
return values;
|
|
472
|
-
}
|
|
473
|
-
const EMPTY_SOURCE = {
|
|
474
|
-
propKeys: [],
|
|
475
|
-
variantKeys: [],
|
|
476
|
-
isComponent: false
|
|
477
|
-
};
|
|
478
|
-
function normalizeKeySource(source) {
|
|
479
|
-
if (Array.isArray(source)) return {
|
|
480
|
-
propKeys: source,
|
|
481
|
-
variantKeys: source,
|
|
482
|
-
isComponent: false
|
|
483
|
-
};
|
|
484
|
-
if (!source) return EMPTY_SOURCE;
|
|
485
|
-
if (typeof source !== "object" && typeof source !== "function") return EMPTY_SOURCE;
|
|
364
|
+
const EMPTY_KEYS = [];
|
|
365
|
+
function isComponentKeySource(source) {
|
|
366
|
+
if (!source) return false;
|
|
367
|
+
if (typeof source !== "object" && typeof source !== "function") return false;
|
|
486
368
|
const typed = source;
|
|
487
|
-
if (typeof typed.getVariants !== "function") return
|
|
488
|
-
if (!Array.isArray(typed.propKeys)) return
|
|
489
|
-
|
|
490
|
-
return {
|
|
491
|
-
propKeys: typed.propKeys,
|
|
492
|
-
variantKeys: typed.variantKeys,
|
|
493
|
-
isComponent: true
|
|
494
|
-
};
|
|
369
|
+
if (typeof typed.getVariants !== "function") return false;
|
|
370
|
+
if (!Array.isArray(typed.propKeys)) return false;
|
|
371
|
+
return Array.isArray(typed.variantKeys);
|
|
495
372
|
}
|
|
496
|
-
/**
|
|
497
|
-
* Splits props into multiple groups based on key sources. Only the first
|
|
498
|
-
* component claims styling props (class/className/style). Subsequent components
|
|
499
|
-
* only receive variant props. Arrays always receive their listed keys but don't
|
|
500
|
-
* claim styling props.
|
|
501
|
-
*/
|
|
502
373
|
function splitPropsImpl(selfKeys, selfIsComponent, props, sources) {
|
|
503
374
|
const sourcesLength = sources.length;
|
|
504
375
|
const results = [];
|
|
@@ -507,22 +378,28 @@ function splitPropsImpl(selfKeys, selfIsComponent, props, sources) {
|
|
|
507
378
|
const selfKeysLength = selfKeys.length;
|
|
508
379
|
for (let i = 0; i < selfKeysLength; i++) {
|
|
509
380
|
const key = selfKeys[i];
|
|
510
|
-
if (key !== void 0 && key
|
|
381
|
+
if (key !== void 0 && hasOwn(props, key)) selfResult[key] = props[key];
|
|
511
382
|
}
|
|
512
383
|
results.push(selfResult);
|
|
513
384
|
const effectiveKeyArrays = [selfKeys];
|
|
514
385
|
for (let s = 0; s < sourcesLength; s++) {
|
|
515
|
-
const source =
|
|
386
|
+
const source = sources[s];
|
|
516
387
|
const sourceResult = {};
|
|
517
|
-
|
|
388
|
+
let sourceIsComponent = false;
|
|
389
|
+
let effectiveKeys;
|
|
390
|
+
if (Array.isArray(source)) effectiveKeys = source;
|
|
391
|
+
else if (isComponentKeySource(source)) {
|
|
392
|
+
sourceIsComponent = true;
|
|
393
|
+
effectiveKeys = stylingClaimed ? source.variantKeys : source.propKeys;
|
|
394
|
+
} else effectiveKeys = EMPTY_KEYS;
|
|
518
395
|
const effectiveKeysLength = effectiveKeys.length;
|
|
519
396
|
for (let i = 0; i < effectiveKeysLength; i++) {
|
|
520
397
|
const key = effectiveKeys[i];
|
|
521
|
-
if (key !== void 0 && key
|
|
398
|
+
if (key !== void 0 && hasOwn(props, key)) sourceResult[key] = props[key];
|
|
522
399
|
}
|
|
523
400
|
results.push(sourceResult);
|
|
524
401
|
effectiveKeyArrays.push(effectiveKeys);
|
|
525
|
-
if (
|
|
402
|
+
if (sourceIsComponent && !stylingClaimed) stylingClaimed = true;
|
|
526
403
|
}
|
|
527
404
|
const rest = {};
|
|
528
405
|
const propKeys = Object.keys(props);
|
|
@@ -542,17 +419,10 @@ function splitPropsImpl(selfKeys, selfIsComponent, props, sources) {
|
|
|
542
419
|
results.push(rest);
|
|
543
420
|
return results;
|
|
544
421
|
}
|
|
545
|
-
/**
|
|
546
|
-
* Splits props into multiple groups based on key sources. Each source gets its
|
|
547
|
-
* own result object containing all its matching keys. The first component
|
|
548
|
-
* source claims styling props (class/className/style). Subsequent components
|
|
549
|
-
* only receive variant props. Arrays receive their listed keys but don't claim
|
|
550
|
-
* styling props. The last element is always the "rest" containing keys not
|
|
551
|
-
* claimed by any source.
|
|
552
|
-
*/
|
|
553
422
|
const splitProps = ((props, source1, ...sources) => {
|
|
554
|
-
|
|
555
|
-
return splitPropsImpl(
|
|
423
|
+
if (Array.isArray(source1)) return splitPropsImpl(source1, false, props, sources);
|
|
424
|
+
if (isComponentKeySource(source1)) return splitPropsImpl(source1.propKeys, true, props, sources);
|
|
425
|
+
return splitPropsImpl(EMPTY_KEYS, false, props, sources);
|
|
556
426
|
});
|
|
557
427
|
function buildPrebuiltVariant(variantDef) {
|
|
558
428
|
if (!isRecordObject(variantDef)) return {
|
|
@@ -563,7 +433,7 @@ function buildPrebuiltVariant(variantDef) {
|
|
|
563
433
|
const values = {};
|
|
564
434
|
let disabledValues = null;
|
|
565
435
|
for (const key in variantDef) {
|
|
566
|
-
if (!
|
|
436
|
+
if (!hasOwn(variantDef, key)) continue;
|
|
567
437
|
const value = variantDef[key];
|
|
568
438
|
if (value === null) {
|
|
569
439
|
if (!disabledValues) disabledValues = /* @__PURE__ */ new Set();
|
|
@@ -578,65 +448,87 @@ function buildPrebuiltVariant(variantDef) {
|
|
|
578
448
|
disabledValues
|
|
579
449
|
};
|
|
580
450
|
}
|
|
581
|
-
/**
|
|
582
|
-
* Creates the cv and cx functions.
|
|
583
|
-
*/
|
|
584
451
|
function create({ transformClass = (className) => className } = {}) {
|
|
585
|
-
const cx = (...classes) => transformClass(clsx(
|
|
452
|
+
const cx = (...classes) => transformClass(clsx(classes));
|
|
586
453
|
const cv = (config = {}) => {
|
|
587
|
-
const variantKeys = collectVariantKeys(config);
|
|
588
|
-
const variantKeysLength = variantKeys.length;
|
|
589
|
-
const disabledVariantKeys = collectDisabledVariantKeys(config);
|
|
590
|
-
const disabledVariantValues = collectDisabledVariantValues(config);
|
|
591
|
-
const hasDisabledVariantKeys = disabledVariantKeys.size > 0;
|
|
592
|
-
const hasDisabledVariantValues = Object.keys(disabledVariantValues).length > 0;
|
|
593
|
-
const hasAnyDisabled = hasDisabledVariantKeys || hasDisabledVariantValues;
|
|
594
|
-
const inputPropsKeys = [
|
|
595
|
-
"class",
|
|
596
|
-
"className",
|
|
597
|
-
"style",
|
|
598
|
-
...variantKeys
|
|
599
|
-
];
|
|
600
454
|
const extend = config.extend;
|
|
601
455
|
const hasExtend = !!extend && extend.length > 0;
|
|
602
456
|
const variants = config.variants;
|
|
603
457
|
const refine = config.refine;
|
|
604
458
|
const baseStyle = config.style;
|
|
605
459
|
const hasBaseStyle = !!baseStyle;
|
|
460
|
+
const variantKeySet = /* @__PURE__ */ new Set();
|
|
461
|
+
const staticDefaults = {};
|
|
462
|
+
const extMetas = [];
|
|
463
|
+
const extBaseClassesArr = [];
|
|
464
|
+
const extIsolated = [];
|
|
465
|
+
let hasIsolatedExt = false;
|
|
466
|
+
if (hasExtend) for (const ext of extend) {
|
|
467
|
+
const extKeys = ext.variantKeys;
|
|
468
|
+
for (let i = 0; i < extKeys.length; i++) {
|
|
469
|
+
const key = extKeys[i];
|
|
470
|
+
if (key === void 0) continue;
|
|
471
|
+
variantKeySet.add(key);
|
|
472
|
+
}
|
|
473
|
+
const meta = ext[META_KEY];
|
|
474
|
+
if (!meta) continue;
|
|
475
|
+
extMetas.push(meta);
|
|
476
|
+
Object.assign(staticDefaults, meta.staticDefaults);
|
|
477
|
+
const isolated = meta.transformClass !== transformClass;
|
|
478
|
+
extIsolated.push(isolated);
|
|
479
|
+
if (isolated) {
|
|
480
|
+
hasIsolatedExt = true;
|
|
481
|
+
extBaseClassesArr.push(meta.transformClass(meta.baseClass));
|
|
482
|
+
} else extBaseClassesArr.push(meta.baseClass);
|
|
483
|
+
}
|
|
484
|
+
const extCount = extMetas.length;
|
|
485
|
+
const disabledVariantKeys = /* @__PURE__ */ new Set();
|
|
486
|
+
const disabledVariantValues = {};
|
|
487
|
+
let hasDisabledVariantValues = false;
|
|
606
488
|
const variantEntryNames = [];
|
|
607
489
|
const variantEntryDefs = [];
|
|
608
490
|
const functionVariantNames = [];
|
|
609
491
|
const functionVariantFns = [];
|
|
610
492
|
if (variants) for (const name in variants) {
|
|
611
|
-
if (!
|
|
493
|
+
if (!hasOwn(variants, name)) continue;
|
|
612
494
|
const variant = variants[name];
|
|
613
|
-
if (variant === null)
|
|
495
|
+
if (variant === null) {
|
|
496
|
+
variantKeySet.delete(name);
|
|
497
|
+
disabledVariantKeys.add(name);
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
variantKeySet.add(name);
|
|
614
501
|
if (typeof variant === "function") {
|
|
615
502
|
functionVariantNames.push(name);
|
|
616
503
|
functionVariantFns.push(variant);
|
|
617
504
|
continue;
|
|
618
505
|
}
|
|
506
|
+
const prebuiltVariant = buildPrebuiltVariant(variant);
|
|
619
507
|
variantEntryNames.push(name);
|
|
620
|
-
variantEntryDefs.push(
|
|
508
|
+
variantEntryDefs.push(prebuiltVariant);
|
|
509
|
+
if (prebuiltVariant.disabledValues) {
|
|
510
|
+
disabledVariantValues[name] = prebuiltVariant.disabledValues;
|
|
511
|
+
hasDisabledVariantValues = true;
|
|
512
|
+
}
|
|
513
|
+
if (prebuiltVariant.values && hasOwn(prebuiltVariant.values, "false") && staticDefaults[name] === void 0) staticDefaults[name] = false;
|
|
621
514
|
}
|
|
515
|
+
const variantKeys = Array.from(variantKeySet);
|
|
516
|
+
const variantKeysLength = variantKeys.length;
|
|
622
517
|
const variantEntryCount = variantEntryNames.length;
|
|
623
518
|
const functionVariantCount = functionVariantNames.length;
|
|
519
|
+
const hasDisabledVariantKeys = disabledVariantKeys.size > 0;
|
|
520
|
+
const hasAnyDisabled = hasDisabledVariantKeys || hasDisabledVariantValues;
|
|
521
|
+
const inputPropsKeys = [
|
|
522
|
+
"class",
|
|
523
|
+
"className",
|
|
524
|
+
"style",
|
|
525
|
+
...variantKeys
|
|
526
|
+
];
|
|
624
527
|
const computedDefaultNames = [];
|
|
625
528
|
const computedDefaultFns = [];
|
|
626
529
|
const defaultVariants = config.defaultVariants;
|
|
627
|
-
const staticDefaults = {};
|
|
628
|
-
if (extend) for (const ext of extend) {
|
|
629
|
-
const meta = getComponentMeta(ext);
|
|
630
|
-
if (meta) Object.assign(staticDefaults, meta.staticDefaults);
|
|
631
|
-
}
|
|
632
|
-
if (variants) for (const name in variants) {
|
|
633
|
-
if (!Object.hasOwn(variants, name)) continue;
|
|
634
|
-
const variantDef = variants[name];
|
|
635
|
-
if (!isRecordObject(variantDef)) continue;
|
|
636
|
-
if (Object.hasOwn(variantDef, "false") && staticDefaults[name] === void 0) staticDefaults[name] = false;
|
|
637
|
-
}
|
|
638
530
|
if (defaultVariants) for (const name in defaultVariants) {
|
|
639
|
-
if (!
|
|
531
|
+
if (!hasOwn(defaultVariants, name)) continue;
|
|
640
532
|
const value = defaultVariants[name];
|
|
641
533
|
if (typeof value === "function") {
|
|
642
534
|
computedDefaultNames.push(name);
|
|
@@ -644,14 +536,14 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
644
536
|
continue;
|
|
645
537
|
}
|
|
646
538
|
if (value === void 0) {
|
|
647
|
-
|
|
539
|
+
delete staticDefaults[name];
|
|
648
540
|
continue;
|
|
649
541
|
}
|
|
650
542
|
staticDefaults[name] = value;
|
|
651
543
|
}
|
|
652
544
|
const computedDefaultCount = computedDefaultNames.length;
|
|
653
545
|
if (hasAnyDisabled) for (const key in staticDefaults) {
|
|
654
|
-
if (!
|
|
546
|
+
if (!hasOwn(staticDefaults, key)) continue;
|
|
655
547
|
if (disabledVariantKeys.has(key)) {
|
|
656
548
|
delete staticDefaults[key];
|
|
657
549
|
continue;
|
|
@@ -662,22 +554,6 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
662
554
|
if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) delete staticDefaults[key];
|
|
663
555
|
}
|
|
664
556
|
}
|
|
665
|
-
const extMetas = [];
|
|
666
|
-
const extBaseClassesArr = [];
|
|
667
|
-
const extIsolated = [];
|
|
668
|
-
let hasIsolatedExt = false;
|
|
669
|
-
if (hasExtend) for (const ext of extend) {
|
|
670
|
-
const meta = getComponentMeta(ext);
|
|
671
|
-
if (!meta) continue;
|
|
672
|
-
extMetas.push(meta);
|
|
673
|
-
const isolated = meta.transformClass !== transformClass;
|
|
674
|
-
extIsolated.push(isolated);
|
|
675
|
-
if (isolated) {
|
|
676
|
-
hasIsolatedExt = true;
|
|
677
|
-
extBaseClassesArr.push(meta.transformClass(meta.baseClass));
|
|
678
|
-
} else extBaseClassesArr.push(meta.baseClass);
|
|
679
|
-
}
|
|
680
|
-
const extCount = extMetas.length;
|
|
681
557
|
const inheritedComputedDefaultKeys = /* @__PURE__ */ new Set();
|
|
682
558
|
for (let i = 0; i < extCount; i++) {
|
|
683
559
|
const keys = extMetas[i].computedDefaultKeys;
|
|
@@ -689,8 +565,7 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
689
565
|
if (meta.resolveRefine) extMetasWithRefine.push(meta);
|
|
690
566
|
}
|
|
691
567
|
const extMetasWithRefineCount = extMetasWithRefine.length;
|
|
692
|
-
const
|
|
693
|
-
const creationFrame = !!refine || computedDefaultCount > 0 || extMetasWithRefineCount > 0 ? captureCreationFrame(cv) : void 0;
|
|
568
|
+
const creationFrame = (!!refine || computedDefaultCount > 0 || extMetasWithRefineCount > 0) && process.env.NODE_ENV !== "production" ? captureCreationFrame(cv) : void 0;
|
|
694
569
|
const functionVariantKeys = /* @__PURE__ */ new Set();
|
|
695
570
|
for (let i = 0; i < extCount; i++) {
|
|
696
571
|
const fnKeys = extMetas[i].functionVariantKeys;
|
|
@@ -703,30 +578,24 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
703
578
|
for (let i = 0; i < variantEntryCount; i++) functionVariantKeys.delete(variantEntryNames[i]);
|
|
704
579
|
const computedDefaultKeys = new Set(inheritedComputedDefaultKeys);
|
|
705
580
|
for (let i = 0; i < computedDefaultCount; i++) computedDefaultKeys.add(computedDefaultNames[i]);
|
|
706
|
-
let
|
|
581
|
+
let staticExtSkipKeys = null;
|
|
582
|
+
if (hasDisabledVariantKeys || functionVariantCount > 0) {
|
|
583
|
+
staticExtSkipKeys = /* @__PURE__ */ new Set();
|
|
584
|
+
for (const k of disabledVariantKeys) staticExtSkipKeys.add(k);
|
|
585
|
+
for (let i = 0; i < functionVariantCount; i++) staticExtSkipKeys.add(functionVariantNames[i]);
|
|
586
|
+
}
|
|
707
587
|
if (variantEntryCount > 0 && extCount > 0) for (let i = 0; i < variantEntryCount; i++) {
|
|
708
588
|
const name = variantEntryNames[i];
|
|
709
589
|
for (let j = 0; j < extCount; j++) if (extMetas[j].functionVariantKeys.has(name)) {
|
|
710
|
-
|
|
711
|
-
|
|
590
|
+
staticExtSkipKeys ??= /* @__PURE__ */ new Set();
|
|
591
|
+
staticExtSkipKeys.add(name);
|
|
712
592
|
break;
|
|
713
593
|
}
|
|
714
594
|
}
|
|
715
|
-
let staticExtSkipKeys = null;
|
|
716
|
-
if (hasDisabledVariantKeys || functionVariantCount > 0 || staticVariantsOverridingExtFn !== null) {
|
|
717
|
-
staticExtSkipKeys = /* @__PURE__ */ new Set();
|
|
718
|
-
for (const k of disabledVariantKeys) staticExtSkipKeys.add(k);
|
|
719
|
-
for (let i = 0; i < functionVariantCount; i++) staticExtSkipKeys.add(functionVariantNames[i]);
|
|
720
|
-
if (staticVariantsOverridingExtFn) for (const k of staticVariantsOverridingExtFn) staticExtSkipKeys.add(k);
|
|
721
|
-
}
|
|
722
595
|
const staticExtSkipValues = hasDisabledVariantValues ? disabledVariantValues : null;
|
|
723
596
|
function filterDisabledInto(input, out) {
|
|
724
|
-
if (!hasAnyDisabled) {
|
|
725
|
-
for (const key in input) if (Object.hasOwn(input, key)) out[key] = input[key];
|
|
726
|
-
return;
|
|
727
|
-
}
|
|
728
597
|
for (const key in input) {
|
|
729
|
-
if (!
|
|
598
|
+
if (!hasOwn(input, key)) continue;
|
|
730
599
|
if (disabledVariantKeys.has(key)) continue;
|
|
731
600
|
const value = input[key];
|
|
732
601
|
if (hasDisabledVariantValues) {
|
|
@@ -748,7 +617,7 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
748
617
|
if (!hasAnyDisabled) return input;
|
|
749
618
|
let hasOwnDisabledValue = false;
|
|
750
619
|
for (const key in input) {
|
|
751
|
-
if (!
|
|
620
|
+
if (!hasOwn(input, key)) continue;
|
|
752
621
|
const value = input[key];
|
|
753
622
|
if (isOwnDisabledValue(key, value)) {
|
|
754
623
|
hasOwnDisabledValue = true;
|
|
@@ -758,7 +627,7 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
758
627
|
if (!hasOwnDisabledValue) return input;
|
|
759
628
|
const filtered = {};
|
|
760
629
|
for (const key in input) {
|
|
761
|
-
if (!
|
|
630
|
+
if (!hasOwn(input, key)) continue;
|
|
762
631
|
const value = input[key];
|
|
763
632
|
if (!isOwnDisabledValue(key, value)) {
|
|
764
633
|
filtered[key] = value;
|
|
@@ -770,10 +639,10 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
770
639
|
return filtered;
|
|
771
640
|
};
|
|
772
641
|
function resolveVariantsHot(propsVariants) {
|
|
773
|
-
const defaults = {};
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
if (!
|
|
642
|
+
const defaults = Object.assign({}, staticDefaults);
|
|
643
|
+
for (let i = 0; i < variantKeysLength; i++) {
|
|
644
|
+
const k = variantKeys[i];
|
|
645
|
+
if (!hasOwn(propsVariants, k)) continue;
|
|
777
646
|
const v = propsVariants[k];
|
|
778
647
|
if (v === void 0) continue;
|
|
779
648
|
defaults[k] = v;
|
|
@@ -784,33 +653,27 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
784
653
|
return result;
|
|
785
654
|
}
|
|
786
655
|
const runComputedDefaults = (resolved, defaultResolved, userVariantProps, filterOwnVariants, protectedVariantKeys) => {
|
|
787
|
-
if (computedDefaultCount === 0) return {
|
|
788
|
-
workingResolved: resolved,
|
|
789
|
-
changedVariants: null
|
|
790
|
-
};
|
|
791
656
|
let ownVariants = filterOwnVariants ? null : resolved;
|
|
792
657
|
const getOwnVariants = () => {
|
|
793
658
|
if (ownVariants) return ownVariants;
|
|
794
659
|
const filteredVariants = {};
|
|
795
660
|
for (let i = 0; i < variantKeysLength; i++) {
|
|
796
661
|
const key = variantKeys[i];
|
|
797
|
-
if (
|
|
662
|
+
if (hasOwn(resolved, key)) filteredVariants[key] = resolved[key];
|
|
798
663
|
}
|
|
799
664
|
ownVariants = filteredVariants;
|
|
800
665
|
return filteredVariants;
|
|
801
666
|
};
|
|
802
667
|
let updatedVariants = null;
|
|
803
|
-
let changedVariants = null;
|
|
804
668
|
const ensureUpdated = () => {
|
|
805
669
|
if (updatedVariants) return updatedVariants;
|
|
806
|
-
const updated = {};
|
|
807
|
-
Object.assign(updated, resolved);
|
|
670
|
+
const updated = Object.assign({}, resolved);
|
|
808
671
|
updatedVariants = updated;
|
|
809
672
|
return updated;
|
|
810
673
|
};
|
|
811
674
|
for (let i = 0; i < computedDefaultCount; i++) {
|
|
812
675
|
const key = computedDefaultNames[i];
|
|
813
|
-
if (
|
|
676
|
+
if (hasOwn(userVariantProps, key)) {
|
|
814
677
|
if (userVariantProps[key] !== void 0) continue;
|
|
815
678
|
}
|
|
816
679
|
if (protectedVariantKeys?.has(key)) continue;
|
|
@@ -823,38 +686,26 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
823
686
|
if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) continue;
|
|
824
687
|
}
|
|
825
688
|
if (value === void 0) {
|
|
826
|
-
if (!
|
|
827
|
-
|
|
828
|
-
changedVariants ??= {};
|
|
829
|
-
changedVariants[key] = value;
|
|
830
|
-
}
|
|
831
|
-
Reflect.deleteProperty(ensureUpdated(), key);
|
|
689
|
+
if (!hasOwn(variantSnapshot, key)) continue;
|
|
690
|
+
delete ensureUpdated()[key];
|
|
832
691
|
continue;
|
|
833
692
|
}
|
|
834
693
|
if (Object.is(variantSnapshot[key], value)) continue;
|
|
835
|
-
if (shouldCollectChangedVariants) {
|
|
836
|
-
changedVariants ??= {};
|
|
837
|
-
changedVariants[key] = value;
|
|
838
|
-
}
|
|
839
694
|
ensureUpdated()[key] = value;
|
|
840
695
|
}
|
|
841
|
-
return
|
|
842
|
-
workingResolved: updatedVariants ?? resolved,
|
|
843
|
-
changedVariants
|
|
844
|
-
};
|
|
696
|
+
return updatedVariants ?? resolved;
|
|
845
697
|
};
|
|
846
|
-
const runRefineContext = (resolved,
|
|
698
|
+
const runRefineContext = (resolved, filterOwnVariants, collectOutput, applyVariantUpdates, protectedVariants, protectedVariantKeys) => {
|
|
847
699
|
let workingResolved = resolved;
|
|
848
700
|
let cClasses = null;
|
|
849
701
|
let cStyle = null;
|
|
850
|
-
let changedVariants = null;
|
|
851
702
|
if (refine) {
|
|
852
703
|
let ownVariants = resolved;
|
|
853
704
|
if (filterOwnVariants) {
|
|
854
705
|
const filteredVariants = {};
|
|
855
706
|
for (let i = 0; i < variantKeysLength; i++) {
|
|
856
707
|
const k = variantKeys[i];
|
|
857
|
-
if (
|
|
708
|
+
if (hasOwn(resolved, k)) filteredVariants[k] = resolved[k];
|
|
858
709
|
}
|
|
859
710
|
ownVariants = filteredVariants;
|
|
860
711
|
}
|
|
@@ -863,48 +714,40 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
863
714
|
let localCStyle = null;
|
|
864
715
|
const ensureUpdated = () => {
|
|
865
716
|
if (updatedVariants) return updatedVariants;
|
|
866
|
-
const u = {};
|
|
867
|
-
Object.assign(u, ownVariants);
|
|
717
|
+
const u = Object.assign({}, ownVariants);
|
|
868
718
|
updatedVariants = u;
|
|
869
719
|
return u;
|
|
870
720
|
};
|
|
871
|
-
const
|
|
872
|
-
if (
|
|
873
|
-
if (!changedVariants) changedVariants = {};
|
|
874
|
-
changedVariants[key] = value;
|
|
875
|
-
}
|
|
876
|
-
if (protect && protectedVariants) {
|
|
721
|
+
const protectVariant = (key, value) => {
|
|
722
|
+
if (protectedVariants) {
|
|
877
723
|
protectedVariants[key] = value;
|
|
878
724
|
protectedVariantKeys?.add(key);
|
|
879
725
|
}
|
|
880
726
|
};
|
|
881
|
-
const getCurrentVariantValue = (key) => {
|
|
882
|
-
return updatedVariants ? updatedVariants[key] : ownVariants[key];
|
|
883
|
-
};
|
|
884
727
|
const result = refine({
|
|
885
728
|
variants: ownVariants,
|
|
886
729
|
setVariants: (newVariants) => {
|
|
887
730
|
if (!applyVariantUpdates) return;
|
|
888
731
|
if (!hasAnyDisabled) {
|
|
889
732
|
for (const key in newVariants) {
|
|
890
|
-
if (!
|
|
733
|
+
if (!hasOwn(newVariants, key)) continue;
|
|
891
734
|
const value = newVariants[key];
|
|
892
|
-
|
|
893
|
-
if (Object.is(
|
|
735
|
+
protectVariant(key, value);
|
|
736
|
+
if (Object.is((updatedVariants ?? ownVariants)[key], value)) continue;
|
|
894
737
|
ensureUpdated()[key] = value;
|
|
895
738
|
}
|
|
896
739
|
return;
|
|
897
740
|
}
|
|
898
741
|
for (const key in newVariants) {
|
|
899
|
-
if (!
|
|
742
|
+
if (!hasOwn(newVariants, key)) continue;
|
|
900
743
|
if (disabledVariantKeys.has(key)) continue;
|
|
901
744
|
const value = newVariants[key];
|
|
902
745
|
if (hasDisabledVariantValues) {
|
|
903
746
|
const valueKey = getVariantValueKey(value);
|
|
904
747
|
if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) continue;
|
|
905
748
|
}
|
|
906
|
-
|
|
907
|
-
if (Object.is(
|
|
749
|
+
protectVariant(key, value);
|
|
750
|
+
if (Object.is((updatedVariants ?? ownVariants)[key], value)) continue;
|
|
908
751
|
ensureUpdated()[key] = value;
|
|
909
752
|
}
|
|
910
753
|
},
|
|
@@ -928,28 +771,22 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
928
771
|
cClasses = localCClasses;
|
|
929
772
|
cStyle = localCStyle;
|
|
930
773
|
if (updatedVariants) {
|
|
931
|
-
const nextResolved = {};
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
const filteredUpdated = {};
|
|
935
|
-
filterDisabledInto(updatedVariants, filteredUpdated);
|
|
936
|
-
Object.assign(nextResolved, filteredUpdated);
|
|
937
|
-
} else Object.assign(nextResolved, updatedVariants);
|
|
774
|
+
const nextResolved = Object.assign({}, workingResolved);
|
|
775
|
+
if (hasAnyDisabled) filterDisabledInto(updatedVariants, nextResolved);
|
|
776
|
+
else Object.assign(nextResolved, updatedVariants);
|
|
938
777
|
workingResolved = nextResolved;
|
|
939
778
|
}
|
|
940
779
|
}
|
|
941
780
|
return {
|
|
942
781
|
workingResolved,
|
|
943
|
-
changedVariants,
|
|
944
782
|
classes: cClasses,
|
|
945
783
|
style: cStyle
|
|
946
784
|
};
|
|
947
785
|
};
|
|
948
|
-
const computeOnce = (resolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut,
|
|
786
|
+
const computeOnce = (resolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut, protectedVariants, protectedVariantKeys, defaultResolved = resolved, renderOnly = false) => {
|
|
949
787
|
let workingResolved = resolved;
|
|
950
788
|
let cClasses = null;
|
|
951
789
|
let cStyle = null;
|
|
952
|
-
let changedVariants = null;
|
|
953
790
|
if (hasExtend) {
|
|
954
791
|
let extSkipKeys;
|
|
955
792
|
if (skipKeys === null) extSkipKeys = staticExtSkipKeys;
|
|
@@ -973,34 +810,26 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
973
810
|
} else extSkipVals[k] = staticExtSkipValues[k];
|
|
974
811
|
}
|
|
975
812
|
}
|
|
976
|
-
const extUserVariantProps = extMetasWithRefineCount > 0 ? getExtUserVariantProps(userVariantProps, protectedVariants ?? null
|
|
813
|
+
const extUserVariantProps = extMetasWithRefineCount > 0 ? getExtUserVariantProps(userVariantProps, protectedVariants ?? null) : userVariantProps;
|
|
977
814
|
for (let i = 0; i < extCount; i++) {
|
|
978
815
|
if (hasIsolatedExt && extIsolated[i]) {
|
|
979
816
|
const extClasses = [];
|
|
980
|
-
workingResolved = extMetas[i].compute(workingResolved, extUserVariantProps, extSkipKeys, extSkipVals, extClasses, styleOut,
|
|
817
|
+
workingResolved = extMetas[i].compute(workingResolved, extUserVariantProps, extSkipKeys, extSkipVals, extClasses, styleOut, protectedVariants, protectedVariantKeys, defaultResolved, renderOnly);
|
|
981
818
|
if (extClasses.length > 0) {
|
|
982
819
|
const joined = clsx(extClasses);
|
|
983
820
|
if (joined.length > 0) classesOut.push(extMetas[i].transformClass(joined));
|
|
984
821
|
}
|
|
985
|
-
} else workingResolved = extMetas[i].compute(workingResolved, extUserVariantProps, extSkipKeys, extSkipVals, classesOut, styleOut,
|
|
822
|
+
} else workingResolved = extMetas[i].compute(workingResolved, extUserVariantProps, extSkipKeys, extSkipVals, classesOut, styleOut, protectedVariants, protectedVariantKeys, defaultResolved, renderOnly);
|
|
986
823
|
workingResolved = filterOwnDisabledVariants(workingResolved, defaultResolved);
|
|
987
824
|
if (protectedVariants && extMetasWithRefineCount > 0) Object.assign(extUserVariantProps, protectedVariants);
|
|
988
825
|
}
|
|
989
826
|
}
|
|
990
|
-
if (!renderOnly && computedDefaultCount > 0)
|
|
991
|
-
const computedResult = runComputedDefaults(workingResolved, defaultResolved, userVariantProps, true, protectedVariantKeys);
|
|
992
|
-
workingResolved = computedResult.workingResolved;
|
|
993
|
-
changedVariants = computedResult.changedVariants;
|
|
994
|
-
}
|
|
827
|
+
if (!renderOnly && computedDefaultCount > 0) workingResolved = runComputedDefaults(workingResolved, defaultResolved, userVariantProps, true, protectedVariantKeys);
|
|
995
828
|
if (refine) {
|
|
996
|
-
const refineResult = runRefineContext(workingResolved,
|
|
829
|
+
const refineResult = runRefineContext(workingResolved, true, true, !renderOnly, protectedVariants, protectedVariantKeys);
|
|
997
830
|
workingResolved = refineResult.workingResolved;
|
|
998
831
|
cClasses = refineResult.classes;
|
|
999
832
|
cStyle = refineResult.style;
|
|
1000
|
-
if (refineResult.changedVariants) {
|
|
1001
|
-
changedVariants ??= {};
|
|
1002
|
-
Object.assign(changedVariants, refineResult.changedVariants);
|
|
1003
|
-
}
|
|
1004
833
|
}
|
|
1005
834
|
if (hasBaseStyle) Object.assign(styleOut, baseStyle);
|
|
1006
835
|
const ownSkipKeys = skipKeys;
|
|
@@ -1014,17 +843,14 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1014
843
|
const variant = variantEntryDefs[i];
|
|
1015
844
|
if (variant.disabledValues && selectedKey != null && variant.disabledValues.has(selectedKey)) continue;
|
|
1016
845
|
if (ownSkipValues && selectedKey != null && ownSkipValues[variantName]?.has(selectedKey)) continue;
|
|
846
|
+
let value;
|
|
1017
847
|
if (variant.values) {
|
|
1018
848
|
if (selectedKey == null) continue;
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
const v = variant.shorthand;
|
|
1025
|
-
if (v.class != null) classesOut.push(v.class);
|
|
1026
|
-
if (v.style) Object.assign(styleOut, v.style);
|
|
1027
|
-
}
|
|
849
|
+
value = variant.values[selectedKey];
|
|
850
|
+
} else if (selectedValue === true) value = variant.shorthand;
|
|
851
|
+
if (!value) continue;
|
|
852
|
+
if (value.class != null) classesOut.push(value.class);
|
|
853
|
+
if (value.style) Object.assign(styleOut, value.style);
|
|
1028
854
|
}
|
|
1029
855
|
for (let i = 0; i < functionVariantCount; i++) {
|
|
1030
856
|
const variantName = functionVariantNames[i];
|
|
@@ -1044,62 +870,44 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1044
870
|
if (cStyle) Object.assign(styleOut, cStyle);
|
|
1045
871
|
return workingResolved;
|
|
1046
872
|
};
|
|
1047
|
-
const compute = !refine && computedDefaultCount === 0 && extMetasWithRefineCount === 0 ? computeOnce : (resolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
873
|
+
const compute = !refine && computedDefaultCount === 0 && extMetasWithRefineCount === 0 ? computeOnce : (resolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut) => {
|
|
874
|
+
let remaining = MAX_REFINE_RUNS;
|
|
875
|
+
const protectedVariants = {};
|
|
876
|
+
const protectedVariantKeys = /* @__PURE__ */ new Set();
|
|
877
|
+
const incomingDefaultResolved = resolved;
|
|
1052
878
|
let workingResolved = resolved;
|
|
1053
879
|
let unstableChanges = null;
|
|
1054
880
|
let lastClasses = [];
|
|
1055
881
|
let lastStyle = {};
|
|
1056
882
|
let isFirstRun = true;
|
|
1057
|
-
while (
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
if (useDirectOutput) {
|
|
1061
|
-
for (const key in styleOut) if (Object.hasOwn(styleOut, key)) {
|
|
1062
|
-
useDirectOutput = false;
|
|
1063
|
-
break;
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
883
|
+
while (remaining > 0) {
|
|
884
|
+
remaining -= 1;
|
|
885
|
+
const useDirectOutput = isFirstRun;
|
|
1066
886
|
const classCount = classesOut.length;
|
|
1067
|
-
const nextPendingProtectedVariants = {};
|
|
1068
887
|
const nextClasses = useDirectOutput ? classesOut : [];
|
|
1069
888
|
const nextStyle = useDirectOutput ? styleOut : {};
|
|
1070
|
-
const defaultResolved = mergeProtectedIntoBase(incomingDefaultResolved, protectedVariants);
|
|
1071
|
-
const nextResolved = computeOnce(workingResolved, userVariantProps, skipKeys, skipValues, nextClasses, nextStyle,
|
|
1072
|
-
|
|
1073
|
-
if (pendingProtectedVariants) protectedChanged = mergeVariants(pendingProtectedVariants, nextPendingProtectedVariants, protectedVariantKeys);
|
|
1074
|
-
else protectedChanged = mergeVariants(protectedVariants, nextPendingProtectedVariants, protectedVariantKeys);
|
|
1075
|
-
if (!protectedChanged && (nextResolved === workingResolved || areVariantsEqual(workingResolved, nextResolved))) {
|
|
889
|
+
const defaultResolved = mergeProtectedIntoBase(incomingDefaultResolved, protectedVariants, protectedVariantKeys);
|
|
890
|
+
const nextResolved = computeOnce(workingResolved, userVariantProps, skipKeys, skipValues, nextClasses, nextStyle, protectedVariants, protectedVariantKeys, defaultResolved);
|
|
891
|
+
if (nextResolved === workingResolved || areVariantsEqual(workingResolved, nextResolved)) {
|
|
1076
892
|
if (nextResolved !== workingResolved) {
|
|
1077
893
|
if (useDirectOutput) {
|
|
1078
894
|
classesOut.length = classCount;
|
|
1079
|
-
for (const key in styleOut) if (
|
|
895
|
+
for (const key in styleOut) if (hasOwn(styleOut, key)) Reflect.deleteProperty(styleOut, key);
|
|
1080
896
|
}
|
|
1081
|
-
computeOnce(nextResolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut,
|
|
897
|
+
computeOnce(nextResolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut, protectedVariants, protectedVariantKeys, defaultResolved, true);
|
|
1082
898
|
} else if (!useDirectOutput) {
|
|
1083
899
|
for (let i = 0; i < nextClasses.length; i++) classesOut.push(nextClasses[i]);
|
|
1084
900
|
Object.assign(styleOut, nextStyle);
|
|
1085
901
|
}
|
|
1086
902
|
return nextResolved;
|
|
1087
903
|
}
|
|
1088
|
-
if (process.env.NODE_ENV !== "production" &&
|
|
904
|
+
if (process.env.NODE_ENV !== "production" && remaining < 10) {
|
|
1089
905
|
if (!unstableChanges) unstableChanges = /* @__PURE__ */ new Map();
|
|
1090
906
|
accumulateUnstableVariantChanges(unstableChanges, workingResolved, nextResolved);
|
|
1091
907
|
}
|
|
1092
|
-
if (useDirectOutput && runState.remaining === 0) {
|
|
1093
|
-
warnRefineLimit({
|
|
1094
|
-
runState,
|
|
1095
|
-
creationFrame,
|
|
1096
|
-
unstableChanges
|
|
1097
|
-
});
|
|
1098
|
-
return nextResolved;
|
|
1099
|
-
}
|
|
1100
908
|
if (useDirectOutput) {
|
|
1101
909
|
classesOut.length = classCount;
|
|
1102
|
-
for (const key in styleOut) if (
|
|
910
|
+
for (const key in styleOut) if (hasOwn(styleOut, key)) Reflect.deleteProperty(styleOut, key);
|
|
1103
911
|
} else {
|
|
1104
912
|
lastClasses = nextClasses;
|
|
1105
913
|
lastStyle = nextStyle;
|
|
@@ -1107,8 +915,7 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1107
915
|
workingResolved = nextResolved;
|
|
1108
916
|
isFirstRun = false;
|
|
1109
917
|
}
|
|
1110
|
-
warnRefineLimit({
|
|
1111
|
-
runState,
|
|
918
|
+
if (process.env.NODE_ENV !== "production") warnRefineLimit({
|
|
1112
919
|
creationFrame,
|
|
1113
920
|
unstableChanges
|
|
1114
921
|
});
|
|
@@ -1116,62 +923,41 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1116
923
|
Object.assign(styleOut, lastStyle);
|
|
1117
924
|
return workingResolved;
|
|
1118
925
|
};
|
|
1119
|
-
const resolveRefineOnce = (resolved, userVariantProps, filterOwnVariants = true,
|
|
926
|
+
const resolveRefineOnce = (resolved, userVariantProps, filterOwnVariants = true, protectedVariants, protectedVariantKeys, defaultResolved = resolved) => {
|
|
1120
927
|
let workingResolved = resolved;
|
|
1121
|
-
let changedVariants = null;
|
|
1122
928
|
if (extMetasWithRefineCount > 0) {
|
|
1123
|
-
const extUserVariantProps = getExtUserVariantProps(userVariantProps, protectedVariants ?? null
|
|
929
|
+
const extUserVariantProps = getExtUserVariantProps(userVariantProps, protectedVariants ?? null);
|
|
1124
930
|
for (let i = 0; i < extMetasWithRefineCount; i++) {
|
|
1125
931
|
const resolveRefine = extMetasWithRefine[i].resolveRefine;
|
|
1126
932
|
if (!resolveRefine) continue;
|
|
1127
|
-
workingResolved = resolveRefine(workingResolved, extUserVariantProps, true,
|
|
933
|
+
workingResolved = resolveRefine(workingResolved, extUserVariantProps, true, protectedVariants, protectedVariantKeys, defaultResolved);
|
|
1128
934
|
workingResolved = filterOwnDisabledVariants(workingResolved, defaultResolved);
|
|
1129
935
|
if (protectedVariants) Object.assign(extUserVariantProps, protectedVariants);
|
|
1130
936
|
}
|
|
1131
937
|
}
|
|
1132
|
-
if (computedDefaultCount > 0)
|
|
1133
|
-
|
|
1134
|
-
workingResolved = computedResult.workingResolved;
|
|
1135
|
-
changedVariants = computedResult.changedVariants;
|
|
1136
|
-
}
|
|
1137
|
-
if (refine) {
|
|
1138
|
-
const refineResult = runRefineContext(workingResolved, userVariantProps, filterOwnVariants, false, true, protectedVariants, pendingProtectedVariants, protectedVariantKeys);
|
|
1139
|
-
workingResolved = refineResult.workingResolved;
|
|
1140
|
-
if (refineResult.changedVariants) {
|
|
1141
|
-
changedVariants ??= {};
|
|
1142
|
-
Object.assign(changedVariants, refineResult.changedVariants);
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
938
|
+
if (computedDefaultCount > 0) workingResolved = runComputedDefaults(workingResolved, defaultResolved, userVariantProps, filterOwnVariants, protectedVariantKeys);
|
|
939
|
+
if (refine) workingResolved = runRefineContext(workingResolved, filterOwnVariants, false, true, protectedVariants, protectedVariantKeys).workingResolved;
|
|
1145
940
|
return workingResolved;
|
|
1146
941
|
};
|
|
1147
|
-
const resolveRefine = refine || computedDefaultCount > 0 || extMetasWithRefineCount > 0 ? (resolved, userVariantProps, filterOwnVariants = true
|
|
1148
|
-
|
|
1149
|
-
protectedVariants
|
|
1150
|
-
protectedVariantKeys
|
|
942
|
+
const resolveRefine = refine || computedDefaultCount > 0 || extMetasWithRefineCount > 0 ? (resolved, userVariantProps, filterOwnVariants = true) => {
|
|
943
|
+
let remaining = MAX_REFINE_RUNS;
|
|
944
|
+
const protectedVariants = {};
|
|
945
|
+
const protectedVariantKeys = /* @__PURE__ */ new Set();
|
|
946
|
+
const incomingDefaultResolved = resolved;
|
|
1151
947
|
let workingResolved = resolved;
|
|
1152
948
|
let unstableChanges = null;
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
const
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
let protectedChanged;
|
|
1160
|
-
if (pendingProtectedVariants) protectedChanged = mergeVariants(pendingProtectedVariants, nextPendingProtectedVariants, protectedVariantKeys);
|
|
1161
|
-
else protectedChanged = mergeVariants(protectedVariants, nextPendingProtectedVariants, protectedVariantKeys);
|
|
1162
|
-
if (!protectedChanged && (nextResolved === workingResolved || areVariantsEqual(workingResolved, nextResolved))) {
|
|
1163
|
-
workingResolved = nextResolved;
|
|
1164
|
-
reachedLimit = false;
|
|
1165
|
-
break;
|
|
1166
|
-
}
|
|
1167
|
-
if (process.env.NODE_ENV !== "production" && runState.remaining < 10) {
|
|
949
|
+
while (remaining > 0) {
|
|
950
|
+
remaining -= 1;
|
|
951
|
+
const defaultResolved = mergeProtectedIntoBase(incomingDefaultResolved, protectedVariants, protectedVariantKeys);
|
|
952
|
+
const nextResolved = resolveRefineOnce(workingResolved, userVariantProps, filterOwnVariants, protectedVariants, protectedVariantKeys, defaultResolved);
|
|
953
|
+
if (nextResolved === workingResolved || areVariantsEqual(workingResolved, nextResolved)) return nextResolved;
|
|
954
|
+
if (process.env.NODE_ENV !== "production" && remaining < 10) {
|
|
1168
955
|
if (!unstableChanges) unstableChanges = /* @__PURE__ */ new Map();
|
|
1169
956
|
accumulateUnstableVariantChanges(unstableChanges, workingResolved, nextResolved);
|
|
1170
957
|
}
|
|
1171
958
|
workingResolved = nextResolved;
|
|
1172
959
|
}
|
|
1173
|
-
if (
|
|
1174
|
-
runState,
|
|
960
|
+
if (process.env.NODE_ENV !== "production") warnRefineLimit({
|
|
1175
961
|
creationFrame,
|
|
1176
962
|
unstableChanges
|
|
1177
963
|
});
|
|
@@ -1186,10 +972,10 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1186
972
|
const variantProps = {};
|
|
1187
973
|
for (let i = 0; i < variantKeysLength; i++) {
|
|
1188
974
|
const key = variantKeys[i];
|
|
1189
|
-
if (
|
|
975
|
+
if (hasOwn(propsRecord, key)) variantProps[key] = propsRecord[key];
|
|
1190
976
|
}
|
|
1191
977
|
for (const k in variantProps) {
|
|
1192
|
-
if (!
|
|
978
|
+
if (!hasOwn(variantProps, k)) continue;
|
|
1193
979
|
const v = variantProps[k];
|
|
1194
980
|
if (v === void 0) continue;
|
|
1195
981
|
resolved[k] = v;
|
|
@@ -1198,7 +984,7 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1198
984
|
} else {
|
|
1199
985
|
for (let i = 0; i < variantKeysLength; i++) {
|
|
1200
986
|
const key = variantKeys[i];
|
|
1201
|
-
if (!
|
|
987
|
+
if (!hasOwn(propsRecord, key)) continue;
|
|
1202
988
|
const v = propsRecord[key];
|
|
1203
989
|
if (v === void 0) continue;
|
|
1204
990
|
resolved[key] = v;
|
|
@@ -1218,15 +1004,8 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1218
1004
|
const psv = propsRecord.style;
|
|
1219
1005
|
if (psv != null) {
|
|
1220
1006
|
if (typeof psv === "string") {
|
|
1221
|
-
if (psv.length > 0)
|
|
1222
|
-
} else if (typeof psv === "object")
|
|
1223
|
-
let hasAnyKey = false;
|
|
1224
|
-
for (const _ in psv) {
|
|
1225
|
-
hasAnyKey = true;
|
|
1226
|
-
break;
|
|
1227
|
-
}
|
|
1228
|
-
if (hasAnyKey) Object.assign(style, normalizeStyle(psv));
|
|
1229
|
-
}
|
|
1007
|
+
if (psv.length > 0) htmlStyleToStyleValue(psv, style);
|
|
1008
|
+
} else if (typeof psv === "object") htmlObjStyleToStyleValue(psv, style);
|
|
1230
1009
|
}
|
|
1231
1010
|
return {
|
|
1232
1011
|
className: transformClass(clsx(allClasses)),
|
|
@@ -1234,20 +1013,28 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1234
1013
|
};
|
|
1235
1014
|
};
|
|
1236
1015
|
const getVariants = (variants) => {
|
|
1237
|
-
const
|
|
1016
|
+
const variantsRecord = variants ?? EMPTY_DEFAULTS;
|
|
1017
|
+
let variantProps = variantsRecord;
|
|
1018
|
+
if (variants && extMetasWithRefineCount > 0) {
|
|
1019
|
+
variantProps = {};
|
|
1020
|
+
for (let i = 0; i < variantKeysLength; i++) {
|
|
1021
|
+
const key = variantKeys[i];
|
|
1022
|
+
if (hasOwn(variantsRecord, key)) variantProps[key] = variantsRecord[key];
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1238
1025
|
let resolvedVariants = resolveVariantsHot(variantProps);
|
|
1239
1026
|
if (resolveRefine) resolvedVariants = resolveRefine(resolvedVariants, variantProps, false);
|
|
1240
1027
|
return resolvedVariants;
|
|
1241
1028
|
};
|
|
1242
|
-
const computedBaseClass = hasExtend ? clsx(
|
|
1029
|
+
const computedBaseClass = hasExtend ? clsx(extBaseClassesArr, config.class) : clsx(config.class);
|
|
1243
1030
|
const classFn = (props = {}) => {
|
|
1244
1031
|
return computeResult(props).className;
|
|
1245
1032
|
};
|
|
1246
1033
|
const meta = {
|
|
1247
1034
|
baseClass: computedBaseClass,
|
|
1248
1035
|
staticDefaults,
|
|
1249
|
-
compute,
|
|
1250
|
-
resolveRefine,
|
|
1036
|
+
compute: computeOnce,
|
|
1037
|
+
resolveRefine: resolveRefine ? resolveRefineOnce : null,
|
|
1251
1038
|
transformClass,
|
|
1252
1039
|
functionVariantKeys,
|
|
1253
1040
|
computedDefaultKeys
|
|
@@ -1258,7 +1045,7 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1258
1045
|
c.getVariants = getVariants;
|
|
1259
1046
|
c.variantKeys = variantKeys;
|
|
1260
1047
|
c.propKeys = propKeys;
|
|
1261
|
-
|
|
1048
|
+
c[META_KEY] = meta;
|
|
1262
1049
|
return c;
|
|
1263
1050
|
};
|
|
1264
1051
|
const defaultComponent = ((props = {}) => {
|
|
@@ -1275,14 +1062,14 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1275
1062
|
const { className, style } = computeResult(props);
|
|
1276
1063
|
return {
|
|
1277
1064
|
className,
|
|
1278
|
-
style
|
|
1065
|
+
style
|
|
1279
1066
|
};
|
|
1280
1067
|
});
|
|
1281
1068
|
initComponent(jsxComponent, [
|
|
1282
1069
|
"className",
|
|
1283
1070
|
"style",
|
|
1284
1071
|
...variantKeys
|
|
1285
|
-
], (props = {}) =>
|
|
1072
|
+
], (props = {}) => computeResult(props).style);
|
|
1286
1073
|
const htmlComponent = ((props = {}) => {
|
|
1287
1074
|
const { className, style } = computeResult(props);
|
|
1288
1075
|
return {
|
|
@@ -1317,7 +1104,10 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1317
1104
|
cx
|
|
1318
1105
|
};
|
|
1319
1106
|
}
|
|
1320
|
-
const
|
|
1107
|
+
const cv = /* @__PURE__ */ (() => create().cv)();
|
|
1108
|
+
function cx(...classes) {
|
|
1109
|
+
return clsx(classes);
|
|
1110
|
+
}
|
|
1321
1111
|
//#endregion
|
|
1322
1112
|
export { create, cv, cx, splitProps };
|
|
1323
1113
|
|