clava 0.5.0 → 0.6.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/CHANGELOG.md +56 -3
- package/README.md +68 -24
- package/dist/index.d.ts +215 -23
- package/dist/index.js +385 -598
- package/dist/index.js.map +1 -1
- package/package.json +17 -2
- package/src/index.ts +364 -642
- package/src/refine-warning.ts +4 -11
- package/src/types.ts +129 -20
- 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 -181
- 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 -1542
- package/tests/solid.test.ts +0 -64
- package/tests/split-props.test.ts +0 -662
- package/tests/variants-inference.test.ts +0 -333
- 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 = {};
|
|
227
|
-
for (const key in style) {
|
|
228
|
-
if (!hasOwn.call(style, key)) continue;
|
|
229
|
-
const value = style[key];
|
|
230
|
-
if (value == null) continue;
|
|
231
|
-
result[hyphenToCamel(key)] = parseLengthValue(value);
|
|
232
|
-
}
|
|
233
|
-
return result;
|
|
234
|
-
}
|
|
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 = {};
|
|
189
|
+
function htmlObjStyleToStyleValue(style, result = {}) {
|
|
243
190
|
for (const key in style) {
|
|
244
|
-
if (!hasOwn
|
|
191
|
+
if (!hasOwn(style, key)) continue;
|
|
245
192
|
const value = style[key];
|
|
246
193
|
if (value == null) continue;
|
|
247
|
-
|
|
194
|
+
const property = hyphenToCamel(key);
|
|
195
|
+
result[property] = normalizeStyleValue(property, value);
|
|
248
196
|
}
|
|
249
197
|
return result;
|
|
250
198
|
}
|
|
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
|
-
for (const key in style) {
|
|
304
|
-
if (!hasOwn.call(style, key)) continue;
|
|
305
|
-
if (key.length >= 2 && key.charCodeAt(0) === 45 && key.charCodeAt(1) === 45) continue;
|
|
306
|
-
if (key.indexOf("-") !== -1) return true;
|
|
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);
|
|
307
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}`;
|
|
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;
|
|
325
|
+
function getExtUserVariantProps(userVariantProps, protectedVariants) {
|
|
326
|
+
return Object.assign({}, userVariantProps, protectedVariants);
|
|
332
327
|
}
|
|
333
|
-
function
|
|
334
|
-
|
|
335
|
-
|
|
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;
|
|
369
|
-
}
|
|
370
|
-
function getComponentMeta(component) {
|
|
371
|
-
return component[META_KEY];
|
|
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,80 +653,59 @@ 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;
|
|
817
680
|
const variantSnapshot = getOwnVariants();
|
|
818
681
|
const defaultValue = inheritedComputedDefaultKeys.has(key) ? variantSnapshot[key] : defaultResolved[key];
|
|
819
|
-
const value = computedDefaultFns[i](
|
|
820
|
-
defaultValue,
|
|
821
|
-
variants: variantSnapshot
|
|
822
|
-
});
|
|
682
|
+
const value = computedDefaultFns[i](defaultValue, variantSnapshot);
|
|
823
683
|
if (hasAnyDisabled) {
|
|
824
684
|
if (disabledVariantKeys.has(key)) continue;
|
|
825
685
|
const valueKey = getVariantValueKey(value);
|
|
826
686
|
if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) continue;
|
|
827
687
|
}
|
|
828
688
|
if (value === void 0) {
|
|
829
|
-
if (!
|
|
830
|
-
|
|
831
|
-
changedVariants ??= {};
|
|
832
|
-
changedVariants[key] = value;
|
|
833
|
-
}
|
|
834
|
-
Reflect.deleteProperty(ensureUpdated(), key);
|
|
689
|
+
if (!hasOwn(variantSnapshot, key)) continue;
|
|
690
|
+
delete ensureUpdated()[key];
|
|
835
691
|
continue;
|
|
836
692
|
}
|
|
837
693
|
if (Object.is(variantSnapshot[key], value)) continue;
|
|
838
|
-
if (shouldCollectChangedVariants) {
|
|
839
|
-
changedVariants ??= {};
|
|
840
|
-
changedVariants[key] = value;
|
|
841
|
-
}
|
|
842
694
|
ensureUpdated()[key] = value;
|
|
843
695
|
}
|
|
844
|
-
return
|
|
845
|
-
workingResolved: updatedVariants ?? resolved,
|
|
846
|
-
changedVariants
|
|
847
|
-
};
|
|
696
|
+
return updatedVariants ?? resolved;
|
|
848
697
|
};
|
|
849
|
-
const runRefineContext = (resolved,
|
|
698
|
+
const runRefineContext = (resolved, filterOwnVariants, collectOutput, applyVariantUpdates, protectedVariants, protectedVariantKeys) => {
|
|
850
699
|
let workingResolved = resolved;
|
|
851
700
|
let cClasses = null;
|
|
852
701
|
let cStyle = null;
|
|
853
|
-
let changedVariants = null;
|
|
854
702
|
if (refine) {
|
|
855
703
|
let ownVariants = resolved;
|
|
856
704
|
if (filterOwnVariants) {
|
|
857
705
|
const filteredVariants = {};
|
|
858
706
|
for (let i = 0; i < variantKeysLength; i++) {
|
|
859
707
|
const k = variantKeys[i];
|
|
860
|
-
if (
|
|
708
|
+
if (hasOwn(resolved, k)) filteredVariants[k] = resolved[k];
|
|
861
709
|
}
|
|
862
710
|
ownVariants = filteredVariants;
|
|
863
711
|
}
|
|
@@ -866,48 +714,40 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
866
714
|
let localCStyle = null;
|
|
867
715
|
const ensureUpdated = () => {
|
|
868
716
|
if (updatedVariants) return updatedVariants;
|
|
869
|
-
const u = {};
|
|
870
|
-
Object.assign(u, ownVariants);
|
|
717
|
+
const u = Object.assign({}, ownVariants);
|
|
871
718
|
updatedVariants = u;
|
|
872
719
|
return u;
|
|
873
720
|
};
|
|
874
|
-
const
|
|
875
|
-
if (
|
|
876
|
-
if (!changedVariants) changedVariants = {};
|
|
877
|
-
changedVariants[key] = value;
|
|
878
|
-
}
|
|
879
|
-
if (protect && protectedVariants) {
|
|
721
|
+
const protectVariant = (key, value) => {
|
|
722
|
+
if (protectedVariants) {
|
|
880
723
|
protectedVariants[key] = value;
|
|
881
724
|
protectedVariantKeys?.add(key);
|
|
882
725
|
}
|
|
883
726
|
};
|
|
884
|
-
const getCurrentVariantValue = (key) => {
|
|
885
|
-
return updatedVariants ? updatedVariants[key] : ownVariants[key];
|
|
886
|
-
};
|
|
887
727
|
const result = refine({
|
|
888
728
|
variants: ownVariants,
|
|
889
729
|
setVariants: (newVariants) => {
|
|
890
730
|
if (!applyVariantUpdates) return;
|
|
891
731
|
if (!hasAnyDisabled) {
|
|
892
732
|
for (const key in newVariants) {
|
|
893
|
-
if (!
|
|
733
|
+
if (!hasOwn(newVariants, key)) continue;
|
|
894
734
|
const value = newVariants[key];
|
|
895
|
-
|
|
896
|
-
if (Object.is(
|
|
735
|
+
protectVariant(key, value);
|
|
736
|
+
if (Object.is((updatedVariants ?? ownVariants)[key], value)) continue;
|
|
897
737
|
ensureUpdated()[key] = value;
|
|
898
738
|
}
|
|
899
739
|
return;
|
|
900
740
|
}
|
|
901
741
|
for (const key in newVariants) {
|
|
902
|
-
if (!
|
|
742
|
+
if (!hasOwn(newVariants, key)) continue;
|
|
903
743
|
if (disabledVariantKeys.has(key)) continue;
|
|
904
744
|
const value = newVariants[key];
|
|
905
745
|
if (hasDisabledVariantValues) {
|
|
906
746
|
const valueKey = getVariantValueKey(value);
|
|
907
747
|
if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) continue;
|
|
908
748
|
}
|
|
909
|
-
|
|
910
|
-
if (Object.is(
|
|
749
|
+
protectVariant(key, value);
|
|
750
|
+
if (Object.is((updatedVariants ?? ownVariants)[key], value)) continue;
|
|
911
751
|
ensureUpdated()[key] = value;
|
|
912
752
|
}
|
|
913
753
|
},
|
|
@@ -931,28 +771,22 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
931
771
|
cClasses = localCClasses;
|
|
932
772
|
cStyle = localCStyle;
|
|
933
773
|
if (updatedVariants) {
|
|
934
|
-
const nextResolved = {};
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
const filteredUpdated = {};
|
|
938
|
-
filterDisabledInto(updatedVariants, filteredUpdated);
|
|
939
|
-
Object.assign(nextResolved, filteredUpdated);
|
|
940
|
-
} else Object.assign(nextResolved, updatedVariants);
|
|
774
|
+
const nextResolved = Object.assign({}, workingResolved);
|
|
775
|
+
if (hasAnyDisabled) filterDisabledInto(updatedVariants, nextResolved);
|
|
776
|
+
else Object.assign(nextResolved, updatedVariants);
|
|
941
777
|
workingResolved = nextResolved;
|
|
942
778
|
}
|
|
943
779
|
}
|
|
944
780
|
return {
|
|
945
781
|
workingResolved,
|
|
946
|
-
changedVariants,
|
|
947
782
|
classes: cClasses,
|
|
948
783
|
style: cStyle
|
|
949
784
|
};
|
|
950
785
|
};
|
|
951
|
-
const computeOnce = (resolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut,
|
|
786
|
+
const computeOnce = (resolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut, protectedVariants, protectedVariantKeys, defaultResolved = resolved, renderOnly = false) => {
|
|
952
787
|
let workingResolved = resolved;
|
|
953
788
|
let cClasses = null;
|
|
954
789
|
let cStyle = null;
|
|
955
|
-
let changedVariants = null;
|
|
956
790
|
if (hasExtend) {
|
|
957
791
|
let extSkipKeys;
|
|
958
792
|
if (skipKeys === null) extSkipKeys = staticExtSkipKeys;
|
|
@@ -976,34 +810,26 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
976
810
|
} else extSkipVals[k] = staticExtSkipValues[k];
|
|
977
811
|
}
|
|
978
812
|
}
|
|
979
|
-
const extUserVariantProps = extMetasWithRefineCount > 0 ? getExtUserVariantProps(userVariantProps, protectedVariants ?? null
|
|
813
|
+
const extUserVariantProps = extMetasWithRefineCount > 0 ? getExtUserVariantProps(userVariantProps, protectedVariants ?? null) : userVariantProps;
|
|
980
814
|
for (let i = 0; i < extCount; i++) {
|
|
981
815
|
if (hasIsolatedExt && extIsolated[i]) {
|
|
982
816
|
const extClasses = [];
|
|
983
|
-
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);
|
|
984
818
|
if (extClasses.length > 0) {
|
|
985
819
|
const joined = clsx(extClasses);
|
|
986
820
|
if (joined.length > 0) classesOut.push(extMetas[i].transformClass(joined));
|
|
987
821
|
}
|
|
988
|
-
} 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);
|
|
989
823
|
workingResolved = filterOwnDisabledVariants(workingResolved, defaultResolved);
|
|
990
824
|
if (protectedVariants && extMetasWithRefineCount > 0) Object.assign(extUserVariantProps, protectedVariants);
|
|
991
825
|
}
|
|
992
826
|
}
|
|
993
|
-
if (!renderOnly && computedDefaultCount > 0)
|
|
994
|
-
const computedResult = runComputedDefaults(workingResolved, defaultResolved, userVariantProps, true, protectedVariantKeys);
|
|
995
|
-
workingResolved = computedResult.workingResolved;
|
|
996
|
-
changedVariants = computedResult.changedVariants;
|
|
997
|
-
}
|
|
827
|
+
if (!renderOnly && computedDefaultCount > 0) workingResolved = runComputedDefaults(workingResolved, defaultResolved, userVariantProps, true, protectedVariantKeys);
|
|
998
828
|
if (refine) {
|
|
999
|
-
const refineResult = runRefineContext(workingResolved,
|
|
829
|
+
const refineResult = runRefineContext(workingResolved, true, true, !renderOnly, protectedVariants, protectedVariantKeys);
|
|
1000
830
|
workingResolved = refineResult.workingResolved;
|
|
1001
831
|
cClasses = refineResult.classes;
|
|
1002
832
|
cStyle = refineResult.style;
|
|
1003
|
-
if (refineResult.changedVariants) {
|
|
1004
|
-
changedVariants ??= {};
|
|
1005
|
-
Object.assign(changedVariants, refineResult.changedVariants);
|
|
1006
|
-
}
|
|
1007
833
|
}
|
|
1008
834
|
if (hasBaseStyle) Object.assign(styleOut, baseStyle);
|
|
1009
835
|
const ownSkipKeys = skipKeys;
|
|
@@ -1017,17 +843,14 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1017
843
|
const variant = variantEntryDefs[i];
|
|
1018
844
|
if (variant.disabledValues && selectedKey != null && variant.disabledValues.has(selectedKey)) continue;
|
|
1019
845
|
if (ownSkipValues && selectedKey != null && ownSkipValues[variantName]?.has(selectedKey)) continue;
|
|
846
|
+
let value;
|
|
1020
847
|
if (variant.values) {
|
|
1021
848
|
if (selectedKey == null) continue;
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
const v = variant.shorthand;
|
|
1028
|
-
if (v.class != null) classesOut.push(v.class);
|
|
1029
|
-
if (v.style) Object.assign(styleOut, v.style);
|
|
1030
|
-
}
|
|
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);
|
|
1031
854
|
}
|
|
1032
855
|
for (let i = 0; i < functionVariantCount; i++) {
|
|
1033
856
|
const variantName = functionVariantNames[i];
|
|
@@ -1047,62 +870,44 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1047
870
|
if (cStyle) Object.assign(styleOut, cStyle);
|
|
1048
871
|
return workingResolved;
|
|
1049
872
|
};
|
|
1050
|
-
const compute = !refine && computedDefaultCount === 0 && extMetasWithRefineCount === 0 ? computeOnce : (resolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
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;
|
|
1055
878
|
let workingResolved = resolved;
|
|
1056
879
|
let unstableChanges = null;
|
|
1057
880
|
let lastClasses = [];
|
|
1058
881
|
let lastStyle = {};
|
|
1059
882
|
let isFirstRun = true;
|
|
1060
|
-
while (
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
if (useDirectOutput) {
|
|
1064
|
-
for (const key in styleOut) if (Object.hasOwn(styleOut, key)) {
|
|
1065
|
-
useDirectOutput = false;
|
|
1066
|
-
break;
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
883
|
+
while (remaining > 0) {
|
|
884
|
+
remaining -= 1;
|
|
885
|
+
const useDirectOutput = isFirstRun;
|
|
1069
886
|
const classCount = classesOut.length;
|
|
1070
|
-
const nextPendingProtectedVariants = {};
|
|
1071
887
|
const nextClasses = useDirectOutput ? classesOut : [];
|
|
1072
888
|
const nextStyle = useDirectOutput ? styleOut : {};
|
|
1073
|
-
const defaultResolved = mergeProtectedIntoBase(incomingDefaultResolved, protectedVariants);
|
|
1074
|
-
const nextResolved = computeOnce(workingResolved, userVariantProps, skipKeys, skipValues, nextClasses, nextStyle,
|
|
1075
|
-
|
|
1076
|
-
if (pendingProtectedVariants) protectedChanged = mergeVariants(pendingProtectedVariants, nextPendingProtectedVariants, protectedVariantKeys);
|
|
1077
|
-
else protectedChanged = mergeVariants(protectedVariants, nextPendingProtectedVariants, protectedVariantKeys);
|
|
1078
|
-
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)) {
|
|
1079
892
|
if (nextResolved !== workingResolved) {
|
|
1080
893
|
if (useDirectOutput) {
|
|
1081
894
|
classesOut.length = classCount;
|
|
1082
|
-
for (const key in styleOut) if (
|
|
895
|
+
for (const key in styleOut) if (hasOwn(styleOut, key)) Reflect.deleteProperty(styleOut, key);
|
|
1083
896
|
}
|
|
1084
|
-
computeOnce(nextResolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut,
|
|
897
|
+
computeOnce(nextResolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut, protectedVariants, protectedVariantKeys, defaultResolved, true);
|
|
1085
898
|
} else if (!useDirectOutput) {
|
|
1086
899
|
for (let i = 0; i < nextClasses.length; i++) classesOut.push(nextClasses[i]);
|
|
1087
900
|
Object.assign(styleOut, nextStyle);
|
|
1088
901
|
}
|
|
1089
902
|
return nextResolved;
|
|
1090
903
|
}
|
|
1091
|
-
if (process.env.NODE_ENV !== "production" &&
|
|
904
|
+
if (process.env.NODE_ENV !== "production" && remaining < 10) {
|
|
1092
905
|
if (!unstableChanges) unstableChanges = /* @__PURE__ */ new Map();
|
|
1093
906
|
accumulateUnstableVariantChanges(unstableChanges, workingResolved, nextResolved);
|
|
1094
907
|
}
|
|
1095
|
-
if (useDirectOutput && runState.remaining === 0) {
|
|
1096
|
-
warnRefineLimit({
|
|
1097
|
-
runState,
|
|
1098
|
-
creationFrame,
|
|
1099
|
-
unstableChanges
|
|
1100
|
-
});
|
|
1101
|
-
return nextResolved;
|
|
1102
|
-
}
|
|
1103
908
|
if (useDirectOutput) {
|
|
1104
909
|
classesOut.length = classCount;
|
|
1105
|
-
for (const key in styleOut) if (
|
|
910
|
+
for (const key in styleOut) if (hasOwn(styleOut, key)) Reflect.deleteProperty(styleOut, key);
|
|
1106
911
|
} else {
|
|
1107
912
|
lastClasses = nextClasses;
|
|
1108
913
|
lastStyle = nextStyle;
|
|
@@ -1110,8 +915,7 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1110
915
|
workingResolved = nextResolved;
|
|
1111
916
|
isFirstRun = false;
|
|
1112
917
|
}
|
|
1113
|
-
warnRefineLimit({
|
|
1114
|
-
runState,
|
|
918
|
+
if (process.env.NODE_ENV !== "production") warnRefineLimit({
|
|
1115
919
|
creationFrame,
|
|
1116
920
|
unstableChanges
|
|
1117
921
|
});
|
|
@@ -1119,62 +923,41 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1119
923
|
Object.assign(styleOut, lastStyle);
|
|
1120
924
|
return workingResolved;
|
|
1121
925
|
};
|
|
1122
|
-
const resolveRefineOnce = (resolved, userVariantProps, filterOwnVariants = true,
|
|
926
|
+
const resolveRefineOnce = (resolved, userVariantProps, filterOwnVariants = true, protectedVariants, protectedVariantKeys, defaultResolved = resolved) => {
|
|
1123
927
|
let workingResolved = resolved;
|
|
1124
|
-
let changedVariants = null;
|
|
1125
928
|
if (extMetasWithRefineCount > 0) {
|
|
1126
|
-
const extUserVariantProps = getExtUserVariantProps(userVariantProps, protectedVariants ?? null
|
|
929
|
+
const extUserVariantProps = getExtUserVariantProps(userVariantProps, protectedVariants ?? null);
|
|
1127
930
|
for (let i = 0; i < extMetasWithRefineCount; i++) {
|
|
1128
931
|
const resolveRefine = extMetasWithRefine[i].resolveRefine;
|
|
1129
932
|
if (!resolveRefine) continue;
|
|
1130
|
-
workingResolved = resolveRefine(workingResolved, extUserVariantProps, true,
|
|
933
|
+
workingResolved = resolveRefine(workingResolved, extUserVariantProps, true, protectedVariants, protectedVariantKeys, defaultResolved);
|
|
1131
934
|
workingResolved = filterOwnDisabledVariants(workingResolved, defaultResolved);
|
|
1132
935
|
if (protectedVariants) Object.assign(extUserVariantProps, protectedVariants);
|
|
1133
936
|
}
|
|
1134
937
|
}
|
|
1135
|
-
if (computedDefaultCount > 0)
|
|
1136
|
-
|
|
1137
|
-
workingResolved = computedResult.workingResolved;
|
|
1138
|
-
changedVariants = computedResult.changedVariants;
|
|
1139
|
-
}
|
|
1140
|
-
if (refine) {
|
|
1141
|
-
const refineResult = runRefineContext(workingResolved, userVariantProps, filterOwnVariants, false, true, protectedVariants, pendingProtectedVariants, protectedVariantKeys);
|
|
1142
|
-
workingResolved = refineResult.workingResolved;
|
|
1143
|
-
if (refineResult.changedVariants) {
|
|
1144
|
-
changedVariants ??= {};
|
|
1145
|
-
Object.assign(changedVariants, refineResult.changedVariants);
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
938
|
+
if (computedDefaultCount > 0) workingResolved = runComputedDefaults(workingResolved, defaultResolved, userVariantProps, filterOwnVariants, protectedVariantKeys);
|
|
939
|
+
if (refine) workingResolved = runRefineContext(workingResolved, filterOwnVariants, false, true, protectedVariants, protectedVariantKeys).workingResolved;
|
|
1148
940
|
return workingResolved;
|
|
1149
941
|
};
|
|
1150
|
-
const resolveRefine = refine || computedDefaultCount > 0 || extMetasWithRefineCount > 0 ? (resolved, userVariantProps, filterOwnVariants = true
|
|
1151
|
-
|
|
1152
|
-
protectedVariants
|
|
1153
|
-
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;
|
|
1154
947
|
let workingResolved = resolved;
|
|
1155
948
|
let unstableChanges = null;
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
const
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
let protectedChanged;
|
|
1163
|
-
if (pendingProtectedVariants) protectedChanged = mergeVariants(pendingProtectedVariants, nextPendingProtectedVariants, protectedVariantKeys);
|
|
1164
|
-
else protectedChanged = mergeVariants(protectedVariants, nextPendingProtectedVariants, protectedVariantKeys);
|
|
1165
|
-
if (!protectedChanged && (nextResolved === workingResolved || areVariantsEqual(workingResolved, nextResolved))) {
|
|
1166
|
-
workingResolved = nextResolved;
|
|
1167
|
-
reachedLimit = false;
|
|
1168
|
-
break;
|
|
1169
|
-
}
|
|
1170
|
-
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) {
|
|
1171
955
|
if (!unstableChanges) unstableChanges = /* @__PURE__ */ new Map();
|
|
1172
956
|
accumulateUnstableVariantChanges(unstableChanges, workingResolved, nextResolved);
|
|
1173
957
|
}
|
|
1174
958
|
workingResolved = nextResolved;
|
|
1175
959
|
}
|
|
1176
|
-
if (
|
|
1177
|
-
runState,
|
|
960
|
+
if (process.env.NODE_ENV !== "production") warnRefineLimit({
|
|
1178
961
|
creationFrame,
|
|
1179
962
|
unstableChanges
|
|
1180
963
|
});
|
|
@@ -1189,10 +972,10 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1189
972
|
const variantProps = {};
|
|
1190
973
|
for (let i = 0; i < variantKeysLength; i++) {
|
|
1191
974
|
const key = variantKeys[i];
|
|
1192
|
-
if (
|
|
975
|
+
if (hasOwn(propsRecord, key)) variantProps[key] = propsRecord[key];
|
|
1193
976
|
}
|
|
1194
977
|
for (const k in variantProps) {
|
|
1195
|
-
if (!
|
|
978
|
+
if (!hasOwn(variantProps, k)) continue;
|
|
1196
979
|
const v = variantProps[k];
|
|
1197
980
|
if (v === void 0) continue;
|
|
1198
981
|
resolved[k] = v;
|
|
@@ -1201,7 +984,7 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1201
984
|
} else {
|
|
1202
985
|
for (let i = 0; i < variantKeysLength; i++) {
|
|
1203
986
|
const key = variantKeys[i];
|
|
1204
|
-
if (!
|
|
987
|
+
if (!hasOwn(propsRecord, key)) continue;
|
|
1205
988
|
const v = propsRecord[key];
|
|
1206
989
|
if (v === void 0) continue;
|
|
1207
990
|
resolved[key] = v;
|
|
@@ -1221,15 +1004,8 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1221
1004
|
const psv = propsRecord.style;
|
|
1222
1005
|
if (psv != null) {
|
|
1223
1006
|
if (typeof psv === "string") {
|
|
1224
|
-
if (psv.length > 0)
|
|
1225
|
-
} else if (typeof psv === "object")
|
|
1226
|
-
let hasAnyKey = false;
|
|
1227
|
-
for (const _ in psv) {
|
|
1228
|
-
hasAnyKey = true;
|
|
1229
|
-
break;
|
|
1230
|
-
}
|
|
1231
|
-
if (hasAnyKey) Object.assign(style, normalizeStyle(psv));
|
|
1232
|
-
}
|
|
1007
|
+
if (psv.length > 0) htmlStyleToStyleValue(psv, style);
|
|
1008
|
+
} else if (typeof psv === "object") htmlObjStyleToStyleValue(psv, style);
|
|
1233
1009
|
}
|
|
1234
1010
|
return {
|
|
1235
1011
|
className: transformClass(clsx(allClasses)),
|
|
@@ -1237,20 +1013,28 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1237
1013
|
};
|
|
1238
1014
|
};
|
|
1239
1015
|
const getVariants = (variants) => {
|
|
1240
|
-
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
|
+
}
|
|
1241
1025
|
let resolvedVariants = resolveVariantsHot(variantProps);
|
|
1242
1026
|
if (resolveRefine) resolvedVariants = resolveRefine(resolvedVariants, variantProps, false);
|
|
1243
1027
|
return resolvedVariants;
|
|
1244
1028
|
};
|
|
1245
|
-
const computedBaseClass = hasExtend ? clsx(
|
|
1029
|
+
const computedBaseClass = hasExtend ? clsx(extBaseClassesArr, config.class) : clsx(config.class);
|
|
1246
1030
|
const classFn = (props = {}) => {
|
|
1247
1031
|
return computeResult(props).className;
|
|
1248
1032
|
};
|
|
1249
1033
|
const meta = {
|
|
1250
1034
|
baseClass: computedBaseClass,
|
|
1251
1035
|
staticDefaults,
|
|
1252
|
-
compute,
|
|
1253
|
-
resolveRefine,
|
|
1036
|
+
compute: computeOnce,
|
|
1037
|
+
resolveRefine: resolveRefine ? resolveRefineOnce : null,
|
|
1254
1038
|
transformClass,
|
|
1255
1039
|
functionVariantKeys,
|
|
1256
1040
|
computedDefaultKeys
|
|
@@ -1261,7 +1045,7 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1261
1045
|
c.getVariants = getVariants;
|
|
1262
1046
|
c.variantKeys = variantKeys;
|
|
1263
1047
|
c.propKeys = propKeys;
|
|
1264
|
-
|
|
1048
|
+
c[META_KEY] = meta;
|
|
1265
1049
|
return c;
|
|
1266
1050
|
};
|
|
1267
1051
|
const defaultComponent = ((props = {}) => {
|
|
@@ -1278,14 +1062,14 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1278
1062
|
const { className, style } = computeResult(props);
|
|
1279
1063
|
return {
|
|
1280
1064
|
className,
|
|
1281
|
-
style
|
|
1065
|
+
style
|
|
1282
1066
|
};
|
|
1283
1067
|
});
|
|
1284
1068
|
initComponent(jsxComponent, [
|
|
1285
1069
|
"className",
|
|
1286
1070
|
"style",
|
|
1287
1071
|
...variantKeys
|
|
1288
|
-
], (props = {}) =>
|
|
1072
|
+
], (props = {}) => computeResult(props).style);
|
|
1289
1073
|
const htmlComponent = ((props = {}) => {
|
|
1290
1074
|
const { className, style } = computeResult(props);
|
|
1291
1075
|
return {
|
|
@@ -1320,7 +1104,10 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1320
1104
|
cx
|
|
1321
1105
|
};
|
|
1322
1106
|
}
|
|
1323
|
-
const
|
|
1107
|
+
const cv = /* @__PURE__ */ (() => create().cv)();
|
|
1108
|
+
function cx(...classes) {
|
|
1109
|
+
return clsx(classes);
|
|
1110
|
+
}
|
|
1324
1111
|
//#endregion
|
|
1325
1112
|
export { create, cv, cx, splitProps };
|
|
1326
1113
|
|