@pandacss/transformer 2.0.0-beta.19 → 2.0.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/css-BPeL3U6s.d.ts +4 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +176 -371
- package/dist/runtime/cx.d.ts +2 -2
- package/dist/runtime/cx.js +181 -52
- package/dist/runtime/internal.d.ts +37 -48
- package/dist/runtime/internal.js +334 -341
- package/dist/runtime/internal.runtime.mjs +278 -1
- package/package.json +3 -3
package/dist/runtime/internal.js
CHANGED
|
@@ -42,76 +42,293 @@ function getMergeKey(className, separator) {
|
|
|
42
42
|
const propStart = lastColon + 1;
|
|
43
43
|
const sepIdx = className.indexOf(separator, propStart);
|
|
44
44
|
if (sepIdx < propStart + 1 || sepIdx >= end) return null;
|
|
45
|
-
|
|
46
|
-
if (lastColon === -1) return property;
|
|
47
|
-
return `${className.slice(0, lastColon)}:${property}`;
|
|
45
|
+
return className.slice(0, sepIdx);
|
|
48
46
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
var CACHE_LIMIT = 2048;
|
|
48
|
+
var CHAR_SPACE = 32;
|
|
49
|
+
var CHAR_BANG = 33;
|
|
50
|
+
var FIELDS = 4;
|
|
51
|
+
function createCache(limit = CACHE_LIMIT) {
|
|
52
|
+
let size = 0;
|
|
53
|
+
let current = /* @__PURE__ */ new Map();
|
|
54
|
+
let previous = /* @__PURE__ */ new Map();
|
|
55
|
+
const set = (key, value) => {
|
|
56
|
+
current.set(key, value);
|
|
57
|
+
if (++size > limit) {
|
|
58
|
+
size = 0;
|
|
59
|
+
previous = current;
|
|
60
|
+
current = /* @__PURE__ */ new Map();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
get(key) {
|
|
65
|
+
let value = current.get(key);
|
|
66
|
+
if (value === void 0 && (value = previous.get(key)) !== void 0) set(key, value);
|
|
67
|
+
return value;
|
|
68
|
+
},
|
|
69
|
+
set
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function scanPart(part, separator, out, offset) {
|
|
73
|
+
let count = 0;
|
|
74
|
+
let clean = part.length > 0;
|
|
75
|
+
let start = 0;
|
|
76
|
+
for (let i = 0; i <= part.length; i++) {
|
|
77
|
+
const code = i === part.length ? CHAR_SPACE : part.charCodeAt(i);
|
|
78
|
+
if (code !== CHAR_SPACE && (code < 9 || code > 13)) continue;
|
|
79
|
+
if (code !== CHAR_SPACE || i === start) clean = false;
|
|
80
|
+
if (i === start) {
|
|
81
|
+
start = i + 1;
|
|
54
82
|
continue;
|
|
55
83
|
}
|
|
56
|
-
|
|
57
|
-
|
|
84
|
+
const at = offset + count * FIELDS;
|
|
85
|
+
count++;
|
|
86
|
+
out[at] = start;
|
|
87
|
+
out[at + 1] = i;
|
|
88
|
+
out[at + 2] = -1;
|
|
89
|
+
let end = i;
|
|
90
|
+
if (part.charCodeAt(end - 1) === CHAR_BANG) end--;
|
|
91
|
+
let depth = 0;
|
|
92
|
+
let propStart = start;
|
|
93
|
+
for (let c = start; c < end; c++) {
|
|
94
|
+
const code2 = part.charCodeAt(c);
|
|
95
|
+
if (code2 === CHAR_OPEN_BRACKET) depth++;
|
|
96
|
+
else if (code2 === CHAR_CLOSE_BRACKET) depth--;
|
|
97
|
+
else if (code2 === CHAR_COLON && depth === 0) propStart = c + 1;
|
|
98
|
+
}
|
|
99
|
+
const sep = part.indexOf(separator, propStart);
|
|
100
|
+
if (sep > propStart && sep < end) {
|
|
101
|
+
let hash = 2166136261;
|
|
102
|
+
for (let c = start; c < sep; c++) hash = Math.imul(hash ^ part.charCodeAt(c), 16777619);
|
|
103
|
+
out[at + 2] = sep;
|
|
104
|
+
out[at + 3] = hash;
|
|
105
|
+
}
|
|
106
|
+
start = i + 1;
|
|
58
107
|
}
|
|
108
|
+
return clean ? count : -count;
|
|
59
109
|
}
|
|
60
|
-
function
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
110
|
+
function createCx(options = {}) {
|
|
111
|
+
const separator = options.separator ?? bakedSeparator;
|
|
112
|
+
const scanned = createCache();
|
|
113
|
+
const seenOnce = createCache(512);
|
|
114
|
+
const parts = [];
|
|
115
|
+
let tokens = new Int32Array(64 * FIELDS);
|
|
116
|
+
let tokenPart = new Int32Array(64);
|
|
117
|
+
let winner = new Int32Array(64);
|
|
118
|
+
let tableSize = 128;
|
|
119
|
+
let table = new Int32Array(tableSize);
|
|
120
|
+
let stamps = new Int32Array(tableSize);
|
|
121
|
+
let stamp = 0;
|
|
122
|
+
function collect(value) {
|
|
123
|
+
if (!value) return;
|
|
124
|
+
if (typeof value === "string") parts.push(value);
|
|
125
|
+
else for (let i = 0; i < value.length; i++) collect(value[i]);
|
|
126
|
+
}
|
|
127
|
+
function reserve(tokenCount) {
|
|
128
|
+
if (tokenCount <= tokenPart.length) return;
|
|
129
|
+
let size = tokenPart.length;
|
|
130
|
+
while (size < tokenCount) size *= 2;
|
|
131
|
+
const grow = (from, length) => {
|
|
132
|
+
const next = new Int32Array(length);
|
|
133
|
+
next.set(from);
|
|
134
|
+
return next;
|
|
135
|
+
};
|
|
136
|
+
tokens = grow(tokens, size * FIELDS);
|
|
137
|
+
tokenPart = grow(tokenPart, size);
|
|
138
|
+
winner = grow(winner, size);
|
|
139
|
+
}
|
|
140
|
+
function sameKey(a, b) {
|
|
141
|
+
const aStart = tokens[a * FIELDS];
|
|
142
|
+
const bStart = tokens[b * FIELDS];
|
|
143
|
+
const length = tokens[a * FIELDS + 2] - aStart;
|
|
144
|
+
if (tokens[b * FIELDS + 2] - bStart !== length) return false;
|
|
145
|
+
const left = parts[tokenPart[a]];
|
|
146
|
+
const right = parts[tokenPart[b]];
|
|
147
|
+
for (let i = 0; i < length; i++) {
|
|
148
|
+
if (left.charCodeAt(aStart + i) !== right.charCodeAt(bStart + i)) return false;
|
|
149
|
+
}
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
function merge() {
|
|
153
|
+
let count = 0;
|
|
154
|
+
let clean = true;
|
|
155
|
+
for (let p = 0; p < parts.length; p++) {
|
|
156
|
+
const part = parts[p];
|
|
157
|
+
const cached = scanned.get(part);
|
|
158
|
+
let partCount;
|
|
159
|
+
if (cached !== void 0) {
|
|
160
|
+
partCount = cached[0];
|
|
161
|
+
reserve(count + Math.abs(partCount));
|
|
162
|
+
const base = count * FIELDS;
|
|
163
|
+
for (let i = 1; i < cached.length; i++) tokens[base + i - 1] = cached[i];
|
|
164
|
+
} else {
|
|
165
|
+
reserve(count + part.length);
|
|
166
|
+
partCount = scanPart(part, separator, tokens, count * FIELDS);
|
|
167
|
+
if (seenOnce.get(part) === void 0) seenOnce.set(part, true);
|
|
168
|
+
else {
|
|
169
|
+
const record = new Int32Array(1 + Math.abs(partCount) * FIELDS);
|
|
170
|
+
record[0] = partCount;
|
|
171
|
+
record.set(tokens.subarray(count * FIELDS, (count + Math.abs(partCount)) * FIELDS), 1);
|
|
172
|
+
scanned.set(part, record);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (partCount <= 0) clean = false;
|
|
176
|
+
const end = count + Math.abs(partCount);
|
|
177
|
+
for (; count < end; count++) tokenPart[count] = p;
|
|
178
|
+
}
|
|
179
|
+
if (count * 2 > tableSize) {
|
|
180
|
+
while (count * 2 > tableSize) tableSize *= 2;
|
|
181
|
+
table = new Int32Array(tableSize);
|
|
182
|
+
stamps = new Int32Array(tableSize);
|
|
183
|
+
stamp = 0;
|
|
184
|
+
}
|
|
185
|
+
if (++stamp === 2147483647) {
|
|
186
|
+
stamp = 1;
|
|
187
|
+
stamps.fill(0);
|
|
188
|
+
}
|
|
189
|
+
const mask = tableSize - 1;
|
|
190
|
+
let replaced = false;
|
|
191
|
+
for (let t = 0; t < count; t++) {
|
|
192
|
+
winner[t] = t;
|
|
193
|
+
if (tokens[t * FIELDS + 2] < 0) continue;
|
|
194
|
+
const hash = tokens[t * FIELDS + 3];
|
|
195
|
+
let slot = hash & mask;
|
|
196
|
+
let owner = -1;
|
|
197
|
+
while (stamps[slot] === stamp) {
|
|
198
|
+
const candidate = table[slot];
|
|
199
|
+
if (tokens[candidate * FIELDS + 3] === hash && sameKey(candidate, t)) {
|
|
200
|
+
owner = candidate;
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
slot = slot + 1 & mask;
|
|
71
204
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (key !== null) {
|
|
76
|
-
if (!seen.has(key)) order.push(key);
|
|
77
|
-
seen.set(key, token);
|
|
205
|
+
if (owner === -1) {
|
|
206
|
+
stamps[slot] = stamp;
|
|
207
|
+
table[slot] = t;
|
|
78
208
|
} else {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
209
|
+
winner[owner] = t;
|
|
210
|
+
winner[t] = -1;
|
|
211
|
+
replaced = true;
|
|
82
212
|
}
|
|
83
213
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return function cx2(...parts) {
|
|
96
|
-
if (parts.length === 1) {
|
|
97
|
-
const only = parts[0];
|
|
98
|
-
if (typeof only === "string") return only;
|
|
99
|
-
if (!only) return "";
|
|
214
|
+
if (!replaced && clean) {
|
|
215
|
+
let joined = parts[0];
|
|
216
|
+
for (let p = 1; p < parts.length; p++) joined += " " + parts[p];
|
|
217
|
+
return joined;
|
|
218
|
+
}
|
|
219
|
+
let result = "";
|
|
220
|
+
for (let t = 0; t < count; t++) {
|
|
221
|
+
const w = winner[t];
|
|
222
|
+
if (w === -1) continue;
|
|
223
|
+
const piece = parts[tokenPart[w]].slice(tokens[w * FIELDS], tokens[w * FIELDS + 1]);
|
|
224
|
+
result = result ? result + " " + piece : piece;
|
|
100
225
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
226
|
+
return result;
|
|
227
|
+
}
|
|
228
|
+
return function cx2(...args) {
|
|
229
|
+
parts.length = 0;
|
|
230
|
+
for (let i = 0; i < args.length; i++) collect(args[i]);
|
|
231
|
+
const count = parts.length;
|
|
232
|
+
if (count === 0) return "";
|
|
233
|
+
if (count === 1) return parts[0];
|
|
234
|
+
return merge();
|
|
106
235
|
};
|
|
107
236
|
}
|
|
108
|
-
var cx = createCx();
|
|
237
|
+
var cx = /* @__PURE__ */ createCx();
|
|
109
238
|
|
|
110
239
|
// src/runtime/internal/css.ts
|
|
111
240
|
function css(...styles) {
|
|
112
241
|
return cx(...styles);
|
|
113
242
|
}
|
|
114
243
|
|
|
244
|
+
// src/runtime/internal/memo.ts
|
|
245
|
+
var TABLE_MAX_SLOTS = 256;
|
|
246
|
+
var RING_ROWS = 16;
|
|
247
|
+
var isMutable = (value) => value !== null && (typeof value === "object" || typeof value === "function");
|
|
248
|
+
var KNOWN_MISSES = ["true", "false", "null"];
|
|
249
|
+
function tableMemo(resolve, keys, variantMap, strict) {
|
|
250
|
+
let slots = 1;
|
|
251
|
+
const radixes = [];
|
|
252
|
+
const trueStates = [];
|
|
253
|
+
const falseStates = [];
|
|
254
|
+
const nullStates = [];
|
|
255
|
+
const states = keys.map((key) => {
|
|
256
|
+
const state = /* @__PURE__ */ Object.create(null);
|
|
257
|
+
let count = 1;
|
|
258
|
+
for (const option of variantMap[key]) state[option] = count++;
|
|
259
|
+
if (strict) {
|
|
260
|
+
trueStates.push(count++);
|
|
261
|
+
falseStates.push(count++);
|
|
262
|
+
nullStates.push(count++);
|
|
263
|
+
} else {
|
|
264
|
+
for (const value of KNOWN_MISSES) state[value] ??= count++;
|
|
265
|
+
trueStates.push(state.true);
|
|
266
|
+
falseStates.push(state.false);
|
|
267
|
+
nullStates.push(state.null);
|
|
268
|
+
}
|
|
269
|
+
radixes.push(count);
|
|
270
|
+
slots *= count;
|
|
271
|
+
return state;
|
|
272
|
+
});
|
|
273
|
+
if (slots > TABLE_MAX_SLOTS) return null;
|
|
274
|
+
const table = new Array(slots);
|
|
275
|
+
let noProps;
|
|
276
|
+
return (props) => {
|
|
277
|
+
if (props == null) return noProps === void 0 ? noProps = resolve() : noProps;
|
|
278
|
+
let slot = 0;
|
|
279
|
+
for (let i = 0; i < keys.length; i++) {
|
|
280
|
+
const value = props[keys[i]];
|
|
281
|
+
let state = 0;
|
|
282
|
+
if (value === true) state = trueStates[i];
|
|
283
|
+
else if (value === false) state = falseStates[i];
|
|
284
|
+
else if (value === null) state = nullStates[i];
|
|
285
|
+
else if (typeof value === "string") state = states[i][value];
|
|
286
|
+
else if (value !== void 0) {
|
|
287
|
+
if (strict || isMutable(value)) return resolve(props);
|
|
288
|
+
state = states[i][String(value)];
|
|
289
|
+
}
|
|
290
|
+
if (state === void 0) return resolve(props);
|
|
291
|
+
slot = slot * radixes[i] + state;
|
|
292
|
+
}
|
|
293
|
+
let result = table[slot];
|
|
294
|
+
if (result === void 0) table[slot] = result = resolve(props);
|
|
295
|
+
return result;
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function ringMemo(resolve, keys) {
|
|
299
|
+
const width = keys.length;
|
|
300
|
+
const values = new Array(RING_ROWS * width);
|
|
301
|
+
const results = new Array(RING_ROWS);
|
|
302
|
+
let written = 0;
|
|
303
|
+
let next = 0;
|
|
304
|
+
let noProps;
|
|
305
|
+
return (props) => {
|
|
306
|
+
if (props == null) return noProps === void 0 ? noProps = resolve() : noProps;
|
|
307
|
+
scan: for (let row = 0; row < written; row++) {
|
|
308
|
+
const start2 = row * width;
|
|
309
|
+
for (let i = 0; i < width; i++) {
|
|
310
|
+
if (props[keys[i]] !== values[start2 + i]) continue scan;
|
|
311
|
+
}
|
|
312
|
+
return results[row];
|
|
313
|
+
}
|
|
314
|
+
for (let i = 0; i < width; i++) {
|
|
315
|
+
if (isMutable(props[keys[i]])) return resolve(props);
|
|
316
|
+
}
|
|
317
|
+
const result = resolve(props);
|
|
318
|
+
const start = next * width;
|
|
319
|
+
for (let i = 0; i < width; i++) values[start + i] = props[keys[i]];
|
|
320
|
+
results[next] = result;
|
|
321
|
+
if (next === written) written++;
|
|
322
|
+
next = (next + 1) % RING_ROWS;
|
|
323
|
+
return result;
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
function memoRecipe(resolve, variantMap, hasCompounds) {
|
|
327
|
+
const keys = Object.keys(variantMap);
|
|
328
|
+
if (keys.length === 0) return resolve;
|
|
329
|
+
return tableMemo(resolve, keys, variantMap, !!hasCompounds) ?? ringMemo(resolve, keys);
|
|
330
|
+
}
|
|
331
|
+
|
|
115
332
|
// src/runtime/internal/shared.ts
|
|
116
333
|
function withDefaults(defaults, props) {
|
|
117
334
|
const out = { ...defaults };
|
|
@@ -120,20 +337,6 @@ function withDefaults(defaults, props) {
|
|
|
120
337
|
}
|
|
121
338
|
return out;
|
|
122
339
|
}
|
|
123
|
-
function splitVariantProps(props, variantKeySet) {
|
|
124
|
-
const rest = {};
|
|
125
|
-
const variantProps = {};
|
|
126
|
-
for (const key in props) {
|
|
127
|
-
if (variantKeySet.has(key)) variantProps[key] = props[key];
|
|
128
|
-
else rest[key] = props[key];
|
|
129
|
-
}
|
|
130
|
-
return [rest, variantProps];
|
|
131
|
-
}
|
|
132
|
-
function toVariantMap(variants) {
|
|
133
|
-
const map = {};
|
|
134
|
-
for (const key in variants) map[key] = Object.keys(variants[key] ?? {});
|
|
135
|
-
return map;
|
|
136
|
-
}
|
|
137
340
|
function compoundMatches(compound, variants) {
|
|
138
341
|
for (const key in compound) {
|
|
139
342
|
if (key === "css" || key === "className" || key === "classNames") continue;
|
|
@@ -147,298 +350,88 @@ function compoundMatches(compound, variants) {
|
|
|
147
350
|
}
|
|
148
351
|
return true;
|
|
149
352
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return (props = {}) => {
|
|
161
|
-
let key = "";
|
|
162
|
-
for (const k in props) {
|
|
163
|
-
const value = props[k];
|
|
164
|
-
if (value !== void 0) key += `${k}:${String(value)}|`;
|
|
165
|
-
}
|
|
166
|
-
if (hasLast && key === lastKey) return lastValue;
|
|
167
|
-
const hit = cache.get(key);
|
|
168
|
-
if (hit !== void 0) {
|
|
169
|
-
lastKey = key;
|
|
170
|
-
lastValue = hit;
|
|
171
|
-
hasLast = true;
|
|
172
|
-
return hit;
|
|
353
|
+
|
|
354
|
+
// src/runtime/internal/recipe.ts
|
|
355
|
+
var isStyleObject = (value) => value != null && typeof value === "object" && !Array.isArray(value);
|
|
356
|
+
function mergeStyles(...styles) {
|
|
357
|
+
const out = {};
|
|
358
|
+
for (const style of styles) {
|
|
359
|
+
if (!isStyleObject(style)) continue;
|
|
360
|
+
for (const key in style) {
|
|
361
|
+
const value = style[key];
|
|
362
|
+
out[key] = isStyleObject(value) ? mergeStyles(out[key], value) : value;
|
|
173
363
|
}
|
|
174
|
-
const out = resolve(props);
|
|
175
|
-
cache.set(key, out);
|
|
176
|
-
if (cache.size > 500) cache.delete(cache.keys().next().value);
|
|
177
|
-
lastKey = key;
|
|
178
|
-
lastValue = out;
|
|
179
|
-
hasLast = true;
|
|
180
|
-
return out;
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
function joinClasses(parts) {
|
|
184
|
-
if (parts.length === 0) return "";
|
|
185
|
-
if (parts.length === 1) return parts[0];
|
|
186
|
-
return cx(...parts);
|
|
187
|
-
}
|
|
188
|
-
function isBooleanBranch(branch) {
|
|
189
|
-
if (!branch) return false;
|
|
190
|
-
const keys = Object.keys(branch);
|
|
191
|
-
return keys.length === 1 && keys[0] === "true" && typeof branch.true === "string";
|
|
192
|
-
}
|
|
193
|
-
function booleanKeys(variants, keys, defaults, hasCompounds) {
|
|
194
|
-
if (hasCompounds || keys.length === 0 || keys.length > 12) return void 0;
|
|
195
|
-
for (const key of keys) {
|
|
196
|
-
if (!isBooleanBranch(variants[key])) return void 0;
|
|
197
|
-
}
|
|
198
|
-
for (const key in defaults) {
|
|
199
|
-
if (!keys.includes(key)) return void 0;
|
|
200
|
-
const value = defaults[key];
|
|
201
|
-
if (value !== true && value !== false && value !== "true" && value !== "false") return void 0;
|
|
202
364
|
}
|
|
203
|
-
return
|
|
204
|
-
}
|
|
205
|
-
function selectsTrue(value) {
|
|
206
|
-
return value === true || value === "true";
|
|
365
|
+
return out;
|
|
207
366
|
}
|
|
208
|
-
function
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
for (
|
|
214
|
-
if (
|
|
367
|
+
function resolveRaw(config, props, pick = (style) => style) {
|
|
368
|
+
const selected = withDefaults(config.defaultVariants ?? {}, props);
|
|
369
|
+
const variants = config.variants ?? {};
|
|
370
|
+
const styles = [pick(config.base)];
|
|
371
|
+
for (const key in selected) styles.push(pick(variants[key]?.[selected[key]]));
|
|
372
|
+
for (const compound of config.compoundVariants ?? []) {
|
|
373
|
+
if (compoundMatches(compound, selected)) styles.push(pick(compound.css));
|
|
215
374
|
}
|
|
216
|
-
|
|
217
|
-
const build = (mask) => {
|
|
218
|
-
const parts = [];
|
|
219
|
-
if (base) parts.push(base);
|
|
220
|
-
for (let i = 0; i < n; i++) {
|
|
221
|
-
if (mask & 1 << i) parts.push(variants[boolKeys[i]].true);
|
|
222
|
-
}
|
|
223
|
-
return joinClasses(parts);
|
|
224
|
-
};
|
|
225
|
-
return (props = {}) => {
|
|
226
|
-
let mask = defaultMask;
|
|
227
|
-
for (let i = 0; i < n; i++) {
|
|
228
|
-
const value = props[boolKeys[i]];
|
|
229
|
-
if (value === void 0) continue;
|
|
230
|
-
if (selectsTrue(value)) mask |= 1 << i;
|
|
231
|
-
else mask &= ~(1 << i);
|
|
232
|
-
}
|
|
233
|
-
return table[mask] ??= build(mask);
|
|
234
|
-
};
|
|
375
|
+
return mergeStyles(...styles);
|
|
235
376
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
const option = options[i];
|
|
241
|
-
const slot = i + 1;
|
|
242
|
-
index.set(option, slot);
|
|
243
|
-
if (option === "true") index.set(true, slot);
|
|
244
|
-
else if (option === "false") index.set(false, slot);
|
|
245
|
-
else {
|
|
246
|
-
const numeric = Number(option);
|
|
247
|
-
if (option !== "" && !Number.isNaN(numeric)) index.set(numeric, slot);
|
|
248
|
-
}
|
|
377
|
+
function resolveSlotRaw(config, props) {
|
|
378
|
+
const result = {};
|
|
379
|
+
for (const slot of config.slots ?? Object.keys(config.base ?? {})) {
|
|
380
|
+
result[slot] = resolveRaw(config, props, (style) => style?.[slot]);
|
|
249
381
|
}
|
|
250
|
-
return
|
|
382
|
+
return result;
|
|
251
383
|
}
|
|
252
|
-
function
|
|
253
|
-
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
const build = (state) => {
|
|
273
|
-
const parts = [];
|
|
274
|
-
if (base) parts.push(base);
|
|
275
|
-
for (const slot of slots) {
|
|
276
|
-
const chosen = Math.floor(state / slot.stride) % slot.radix;
|
|
277
|
-
if (chosen === 0) continue;
|
|
278
|
-
const cls = variants[slot.key][slot.options[chosen - 1]];
|
|
279
|
-
if (cls) parts.push(cls);
|
|
280
|
-
}
|
|
281
|
-
return joinClasses(parts);
|
|
282
|
-
};
|
|
283
|
-
return (props = {}) => {
|
|
284
|
-
let state = defaultState;
|
|
285
|
-
for (let i = 0; i < slots.length; i++) {
|
|
286
|
-
const slot = slots[i];
|
|
287
|
-
const value = props[slot.key];
|
|
288
|
-
if (value === void 0) continue;
|
|
289
|
-
const chosen = slot.index.get(value) ?? 0;
|
|
290
|
-
const current = Math.floor(state / slot.stride) % slot.radix;
|
|
291
|
-
state += (chosen - current) * slot.stride;
|
|
292
|
-
}
|
|
293
|
-
return table[state] ??= build(state);
|
|
384
|
+
function mergeRecipes(parent, child) {
|
|
385
|
+
const defaultVariants = { ...parent.config?.defaultVariants, ...child.config?.defaultVariants };
|
|
386
|
+
const variantKeys = [.../* @__PURE__ */ new Set([...parent.variantKeys ?? [], ...child.variantKeys ?? []])];
|
|
387
|
+
const resolve = (props = {}) => withDefaults(defaultVariants, props);
|
|
388
|
+
const merged = attachRecipe(
|
|
389
|
+
(props) => {
|
|
390
|
+
const selected = resolve(props);
|
|
391
|
+
return cx(parent(selected), child(selected));
|
|
392
|
+
},
|
|
393
|
+
// Compounds from either side rule out the coercing table memo.
|
|
394
|
+
{
|
|
395
|
+
defaultVariants,
|
|
396
|
+
compoundVariants: [...parent.config?.compoundVariants ?? [], ...child.config?.compoundVariants ?? []]
|
|
397
|
+
},
|
|
398
|
+
variantKeys,
|
|
399
|
+
{ ...parent.variantMap, ...child.variantMap }
|
|
400
|
+
);
|
|
401
|
+
merged.raw = (props) => {
|
|
402
|
+
const selected = resolve(props);
|
|
403
|
+
return mergeStyles(parent.raw(selected), child.raw(selected));
|
|
294
404
|
};
|
|
405
|
+
return merged;
|
|
295
406
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
303
|
-
return keys;
|
|
304
|
-
}
|
|
305
|
-
function cva(config) {
|
|
306
|
-
const base = config.base ?? "";
|
|
307
|
-
const variants = config.variants ?? {};
|
|
308
|
-
const defaultVariants = config.defaultVariants ?? {};
|
|
309
|
-
const compoundVariants = config.compoundVariants ?? [];
|
|
310
|
-
const variantKeys = Object.keys(variants);
|
|
311
|
-
const variantKeySet = new Set(variantKeys);
|
|
312
|
-
const hasDefaults = Object.keys(defaultVariants).length > 0;
|
|
313
|
-
const hasCompounds = compoundVariants.length > 0;
|
|
314
|
-
const resolve = (props = {}) => {
|
|
315
|
-
const computed = hasDefaults ? withDefaults(defaultVariants, props) : props;
|
|
316
|
-
const parts = [];
|
|
317
|
-
if (base) parts.push(base);
|
|
318
|
-
for (const key of variantKeys) {
|
|
319
|
-
const cls = variantClass(variants, key, computed[key]);
|
|
320
|
-
if (cls) parts.push(cls);
|
|
321
|
-
}
|
|
322
|
-
if (hasCompounds) {
|
|
323
|
-
for (const compound of compoundVariants) {
|
|
324
|
-
if (!compoundMatches(compound, computed)) continue;
|
|
325
|
-
const cls = compound.className ?? compound.css;
|
|
326
|
-
if (typeof cls === "string" && cls) parts.push(cls);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
return joinClasses(parts);
|
|
330
|
-
};
|
|
331
|
-
const cvaFn = booleanBitset(base, variants, variantKeys, defaultVariants, hasCompounds) ?? variantTable(base, variants, variantKeys, defaultVariants, hasCompounds) ?? memoProps(resolve);
|
|
332
|
-
const merge = (other) => {
|
|
333
|
-
const override = other.config;
|
|
334
|
-
const overrideVariants = override.variants ?? {};
|
|
335
|
-
const mergedVariants = {};
|
|
336
|
-
for (const key of unionKeys(other.variantKeys, variantKeys)) {
|
|
337
|
-
const group = { ...variants[key] };
|
|
338
|
-
const theirs = overrideVariants[key] ?? {};
|
|
339
|
-
for (const option in theirs) {
|
|
340
|
-
const mine = group[option];
|
|
341
|
-
group[option] = mine ? cx(mine, theirs[option]) : theirs[option];
|
|
342
|
-
}
|
|
343
|
-
mergedVariants[key] = group;
|
|
344
|
-
}
|
|
345
|
-
return cva({
|
|
346
|
-
base: cx(base, override.base),
|
|
347
|
-
variants: mergedVariants,
|
|
348
|
-
defaultVariants: { ...defaultVariants, ...override.defaultVariants },
|
|
349
|
-
compoundVariants: [...compoundVariants, ...override.compoundVariants ?? []]
|
|
350
|
-
});
|
|
351
|
-
};
|
|
352
|
-
return Object.assign(cvaFn, {
|
|
353
|
-
__cva__: true,
|
|
407
|
+
function attachRecipe(fn, config, variantKeys, variantMap, classNameMap) {
|
|
408
|
+
const recipeConfig = config;
|
|
409
|
+
const defaults = recipeConfig.defaultVariants ?? {};
|
|
410
|
+
const recipe = memoRecipe(fn, variantMap, recipeConfig.compoundVariants?.length);
|
|
411
|
+
return Object.assign(recipe, {
|
|
412
|
+
__cva__: !classNameMap,
|
|
354
413
|
variantKeys,
|
|
355
|
-
variantMap
|
|
356
|
-
|
|
357
|
-
merge,
|
|
414
|
+
variantMap,
|
|
415
|
+
...classNameMap && { classNameMap },
|
|
358
416
|
config,
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
for (const key in variants) {
|
|
369
|
-
const options = {};
|
|
370
|
-
for (const option in variants[key]) {
|
|
371
|
-
const value = variants[key][option];
|
|
372
|
-
const cls = typeof value === "string" ? value : value?.[slot];
|
|
373
|
-
if (cls) options[option] = cls;
|
|
374
|
-
}
|
|
375
|
-
out[key] = options;
|
|
376
|
-
}
|
|
377
|
-
return out;
|
|
378
|
-
}
|
|
379
|
-
function compoundsForSlot(compounds, slot) {
|
|
380
|
-
if (!compounds?.length) return void 0;
|
|
381
|
-
const out = [];
|
|
382
|
-
for (const compound of compounds) {
|
|
383
|
-
const next = {};
|
|
384
|
-
for (const key in compound) {
|
|
385
|
-
if (key === "css" || key === "className" || key === "classNames") continue;
|
|
386
|
-
next[key] = compound[key];
|
|
417
|
+
raw: (props = {}) => classNameMap ? resolveSlotRaw(recipeConfig, props) : resolveRaw(recipeConfig, props),
|
|
418
|
+
// The styled factory passes its own `cva`, so chains merge exactly like styled-system.
|
|
419
|
+
merge: (other, cva) => cva ? cva(config).merge(other) : mergeRecipes(recipe, other),
|
|
420
|
+
getVariantProps: (props = {}) => withDefaults(defaults, props),
|
|
421
|
+
splitVariantProps: (props) => {
|
|
422
|
+
const variantProps = {};
|
|
423
|
+
const restProps = {};
|
|
424
|
+
for (const key in props) (variantKeys.includes(key) ? variantProps : restProps)[key] = props[key];
|
|
425
|
+
return [variantProps, restProps];
|
|
387
426
|
}
|
|
388
|
-
const css2 = compound.css;
|
|
389
|
-
if (typeof css2 === "string") next.css = css2;
|
|
390
|
-
else if (css2 && typeof css2 === "object" && slot in css2) next.css = css2[slot];
|
|
391
|
-
const className = compound.classNames?.[slot] ?? compound.className;
|
|
392
|
-
if (className) next.className = className;
|
|
393
|
-
if (next.css || next.className) out.push(next);
|
|
394
|
-
}
|
|
395
|
-
return out.length ? out : void 0;
|
|
396
|
-
}
|
|
397
|
-
function sva(config) {
|
|
398
|
-
const slots = config.slots ?? Object.keys(config.base ?? {});
|
|
399
|
-
const defaultVariants = config.defaultVariants ?? {};
|
|
400
|
-
const variantKeys = Object.keys(config.variants ?? {});
|
|
401
|
-
const variantKeySet = new Set(variantKeys);
|
|
402
|
-
const slotFns = slots.map((slot) => {
|
|
403
|
-
let base = config.base?.[slot];
|
|
404
|
-
if (config.className?.[slot]) base = cx(base, config.className[slot]);
|
|
405
|
-
return [
|
|
406
|
-
slot,
|
|
407
|
-
cva({
|
|
408
|
-
base,
|
|
409
|
-
variants: variantsForSlot(config.variants, slot),
|
|
410
|
-
defaultVariants: config.defaultVariants,
|
|
411
|
-
compoundVariants: compoundsForSlot(config.compoundVariants, slot)
|
|
412
|
-
})
|
|
413
|
-
];
|
|
414
|
-
});
|
|
415
|
-
const resolve = (props = {}) => {
|
|
416
|
-
const result = {};
|
|
417
|
-
for (const [slot, fn] of slotFns) result[slot] = fn(props);
|
|
418
|
-
return result;
|
|
419
|
-
};
|
|
420
|
-
const raw = (props = {}) => {
|
|
421
|
-
const result = {};
|
|
422
|
-
for (const [slot, fn] of slotFns) result[slot] = fn.raw(props);
|
|
423
|
-
return result;
|
|
424
|
-
};
|
|
425
|
-
return Object.assign(memoProps(resolve), {
|
|
426
|
-
__cva__: false,
|
|
427
|
-
raw,
|
|
428
|
-
config,
|
|
429
|
-
variantMap: Object.fromEntries(variantKeys.map((key) => [key, Object.keys(config.variants?.[key] ?? {})])),
|
|
430
|
-
variantKeys,
|
|
431
|
-
classNameMap: config.className ?? {},
|
|
432
|
-
getVariantProps: (props) => withDefaults(defaultVariants, props),
|
|
433
|
-
splitVariantProps: (props) => splitVariantProps(props, variantKeySet)
|
|
434
427
|
});
|
|
435
428
|
}
|
|
436
429
|
export {
|
|
430
|
+
attachRecipe,
|
|
437
431
|
createCx,
|
|
438
432
|
css,
|
|
439
|
-
cva,
|
|
440
433
|
cx,
|
|
441
434
|
getMergeKey,
|
|
442
|
-
|
|
443
|
-
|
|
435
|
+
memoRecipe,
|
|
436
|
+
splitClassName
|
|
444
437
|
};
|