@pandacss/transformer 2.0.0-beta.11 → 2.0.0-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +238 -77
- package/dist/runtime/cx.js +7 -0
- package/dist/runtime/internal.d.ts +19 -10
- package/dist/runtime/internal.js +237 -76
- package/dist/runtime/internal.runtime.mjs +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -93,8 +93,15 @@ function mergeClassStrings(separator, classes) {
|
|
|
93
93
|
function createCx(options = {}) {
|
|
94
94
|
const separator = options.separator ?? bakedSeparator;
|
|
95
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 "";
|
|
100
|
+
}
|
|
96
101
|
const flat = [];
|
|
97
102
|
flattenParts(parts, flat);
|
|
103
|
+
if (flat.length === 0) return "";
|
|
104
|
+
if (flat.length === 1) return flat[0];
|
|
98
105
|
return mergeClassStrings(separator, flat);
|
|
99
106
|
};
|
|
100
107
|
}
|
|
@@ -105,7 +112,7 @@ function css(...styles) {
|
|
|
105
112
|
return cx(...styles);
|
|
106
113
|
}
|
|
107
114
|
|
|
108
|
-
// src/runtime/internal/
|
|
115
|
+
// src/runtime/internal/shared.ts
|
|
109
116
|
function withDefaults(defaults, props) {
|
|
110
117
|
const out = { ...defaults };
|
|
111
118
|
for (const key in props) {
|
|
@@ -113,6 +120,20 @@ function withDefaults(defaults, props) {
|
|
|
113
120
|
}
|
|
114
121
|
return out;
|
|
115
122
|
}
|
|
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
|
+
}
|
|
116
137
|
function compoundMatches(compound, variants) {
|
|
117
138
|
for (const key in compound) {
|
|
118
139
|
if (key === "css" || key === "className" || key === "classNames") continue;
|
|
@@ -126,10 +147,160 @@ function compoundMatches(compound, variants) {
|
|
|
126
147
|
}
|
|
127
148
|
return true;
|
|
128
149
|
}
|
|
129
|
-
function
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return
|
|
150
|
+
function variantClass(variants, key, value) {
|
|
151
|
+
if (value == null) return void 0;
|
|
152
|
+
const cls = variants[key]?.[value];
|
|
153
|
+
return typeof cls === "string" && cls ? cls : void 0;
|
|
154
|
+
}
|
|
155
|
+
function memoProps(resolve) {
|
|
156
|
+
const cache = /* @__PURE__ */ new Map();
|
|
157
|
+
let lastKey = "";
|
|
158
|
+
let lastValue;
|
|
159
|
+
let hasLast = false;
|
|
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;
|
|
173
|
+
}
|
|
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
|
+
}
|
|
203
|
+
return keys;
|
|
204
|
+
}
|
|
205
|
+
function selectsTrue(value) {
|
|
206
|
+
return value === true || value === "true";
|
|
207
|
+
}
|
|
208
|
+
function booleanBitset(base, variants, keys, defaults, hasCompounds) {
|
|
209
|
+
const boolKeys = booleanKeys(variants, keys, defaults, hasCompounds);
|
|
210
|
+
if (!boolKeys) return void 0;
|
|
211
|
+
const n = boolKeys.length;
|
|
212
|
+
let defaultMask = 0;
|
|
213
|
+
for (let i = 0; i < n; i++) {
|
|
214
|
+
if (selectsTrue(defaults[boolKeys[i]])) defaultMask |= 1 << i;
|
|
215
|
+
}
|
|
216
|
+
const table = new Array(1 << n);
|
|
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
|
+
};
|
|
235
|
+
}
|
|
236
|
+
var MAX_VARIANT_STATES = 4096;
|
|
237
|
+
function optionIndex(options) {
|
|
238
|
+
const index = /* @__PURE__ */ new Map();
|
|
239
|
+
for (let i = 0; i < options.length; i++) {
|
|
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
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return index;
|
|
251
|
+
}
|
|
252
|
+
function variantTable(base, variants, keys, defaults, hasCompounds) {
|
|
253
|
+
if (hasCompounds || keys.length === 0) return void 0;
|
|
254
|
+
const slots = [];
|
|
255
|
+
let states = 1;
|
|
256
|
+
for (const key of keys) {
|
|
257
|
+
const options = Object.keys(variants[key] ?? {});
|
|
258
|
+
if (options.length === 0) return void 0;
|
|
259
|
+
slots.push({ key, options, index: optionIndex(options), radix: options.length + 1, stride: states });
|
|
260
|
+
states *= options.length + 1;
|
|
261
|
+
if (states > MAX_VARIANT_STATES) return void 0;
|
|
262
|
+
}
|
|
263
|
+
let defaultState = 0;
|
|
264
|
+
for (const key in defaults) {
|
|
265
|
+
const slot = slots.find((candidate) => candidate.key === key);
|
|
266
|
+
if (!slot) return void 0;
|
|
267
|
+
const chosen = slot.index.get(defaults[key]);
|
|
268
|
+
if (chosen === void 0) return void 0;
|
|
269
|
+
defaultState += chosen * slot.stride;
|
|
270
|
+
}
|
|
271
|
+
const table = new Array(states);
|
|
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);
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// src/runtime/internal/cva.ts
|
|
298
|
+
function unionKeys(other, own) {
|
|
299
|
+
const keys = [...other];
|
|
300
|
+
for (const key of own) {
|
|
301
|
+
if (!keys.includes(key)) keys.push(key);
|
|
302
|
+
}
|
|
303
|
+
return keys;
|
|
133
304
|
}
|
|
134
305
|
function cva(config) {
|
|
135
306
|
const base = config.base ?? "";
|
|
@@ -138,49 +309,63 @@ function cva(config) {
|
|
|
138
309
|
const compoundVariants = config.compoundVariants ?? [];
|
|
139
310
|
const variantKeys = Object.keys(variants);
|
|
140
311
|
const variantKeySet = new Set(variantKeys);
|
|
312
|
+
const hasDefaults = Object.keys(defaultVariants).length > 0;
|
|
313
|
+
const hasCompounds = compoundVariants.length > 0;
|
|
141
314
|
const resolve = (props = {}) => {
|
|
142
|
-
const computed = withDefaults(defaultVariants, props);
|
|
315
|
+
const computed = hasDefaults ? withDefaults(defaultVariants, props) : props;
|
|
143
316
|
const parts = [];
|
|
144
317
|
if (base) parts.push(base);
|
|
145
318
|
for (const key of variantKeys) {
|
|
146
|
-
const
|
|
147
|
-
if (
|
|
148
|
-
|
|
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);
|
|
149
327
|
}
|
|
150
328
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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;
|
|
155
344
|
}
|
|
156
|
-
return
|
|
345
|
+
return cva({
|
|
346
|
+
base: cx(base, override.base),
|
|
347
|
+
variants: mergedVariants,
|
|
348
|
+
defaultVariants: { ...defaultVariants, ...override.defaultVariants },
|
|
349
|
+
compoundVariants: [...compoundVariants, ...override.compoundVariants ?? []]
|
|
350
|
+
});
|
|
157
351
|
};
|
|
158
|
-
const cvaFn = (props = {}) => resolve(props);
|
|
159
352
|
return Object.assign(cvaFn, {
|
|
160
353
|
__cva__: true,
|
|
161
354
|
variantKeys,
|
|
162
355
|
variantMap: toVariantMap(variants),
|
|
163
356
|
raw: resolve,
|
|
357
|
+
merge,
|
|
164
358
|
config,
|
|
165
|
-
getVariantProps(props)
|
|
166
|
-
|
|
167
|
-
},
|
|
168
|
-
splitVariantProps(props) {
|
|
169
|
-
const rest = {};
|
|
170
|
-
const variantProps = {};
|
|
171
|
-
for (const key in props) {
|
|
172
|
-
if (variantKeySet.has(key)) variantProps[key] = props[key];
|
|
173
|
-
else rest[key] = props[key];
|
|
174
|
-
}
|
|
175
|
-
return [rest, variantProps];
|
|
176
|
-
}
|
|
359
|
+
getVariantProps: (props) => withDefaults(defaultVariants, props),
|
|
360
|
+
splitVariantProps: (props) => splitVariantProps(props, variantKeySet)
|
|
177
361
|
});
|
|
178
362
|
}
|
|
179
363
|
|
|
180
364
|
// src/runtime/internal/sva.ts
|
|
181
|
-
function
|
|
182
|
-
if (!
|
|
183
|
-
|
|
365
|
+
function compoundsForSlot(compounds, slot) {
|
|
366
|
+
if (!compounds?.length) return void 0;
|
|
367
|
+
const out = [];
|
|
368
|
+
for (const compound of compounds) {
|
|
184
369
|
const next = {};
|
|
185
370
|
for (const key in compound) {
|
|
186
371
|
if (key === "css" || key === "className" || key === "classNames") continue;
|
|
@@ -191,76 +376,52 @@ function slotCompoundVariants(compoundVariants, slot) {
|
|
|
191
376
|
else if (css2 && typeof css2 === "object" && slot in css2) next.css = css2[slot];
|
|
192
377
|
const className = compound.classNames?.[slot] ?? compound.className;
|
|
193
378
|
if (className) next.className = className;
|
|
194
|
-
|
|
195
|
-
}).filter((compound) => compound.css || compound.className);
|
|
196
|
-
}
|
|
197
|
-
function getSlotRecipes(config) {
|
|
198
|
-
const slots = config.slots ?? Object.keys(config.base ?? {});
|
|
199
|
-
const recipes = {};
|
|
200
|
-
for (const slot of slots) {
|
|
201
|
-
recipes[slot] = {
|
|
202
|
-
base: config.base?.[slot],
|
|
203
|
-
variants: config.variants,
|
|
204
|
-
defaultVariants: config.defaultVariants,
|
|
205
|
-
compoundVariants: slotCompoundVariants(config.compoundVariants, slot)
|
|
206
|
-
};
|
|
207
|
-
if (config.className?.[slot]) {
|
|
208
|
-
recipes[slot] = {
|
|
209
|
-
...recipes[slot],
|
|
210
|
-
base: cx(recipes[slot]?.base, config.className[slot])
|
|
211
|
-
};
|
|
212
|
-
}
|
|
379
|
+
if (next.css || next.className) out.push(next);
|
|
213
380
|
}
|
|
214
|
-
return
|
|
381
|
+
return out.length ? out : void 0;
|
|
215
382
|
}
|
|
216
383
|
function sva(config) {
|
|
217
|
-
const
|
|
218
|
-
const slots = Object.entries(slotRecipes).map(([slot, recipe]) => [slot, cva(recipe)]);
|
|
384
|
+
const slots = config.slots ?? Object.keys(config.base ?? {});
|
|
219
385
|
const defaultVariants = config.defaultVariants ?? {};
|
|
220
386
|
const variantKeys = Object.keys(config.variants ?? {});
|
|
221
387
|
const variantKeySet = new Set(variantKeys);
|
|
222
|
-
const
|
|
388
|
+
const slotFns = slots.map((slot) => {
|
|
389
|
+
let base = config.base?.[slot];
|
|
390
|
+
if (config.className?.[slot]) base = cx(base, config.className[slot]);
|
|
391
|
+
return [
|
|
392
|
+
slot,
|
|
393
|
+
cva({
|
|
394
|
+
base,
|
|
395
|
+
variants: config.variants,
|
|
396
|
+
defaultVariants: config.defaultVariants,
|
|
397
|
+
compoundVariants: compoundsForSlot(config.compoundVariants, slot)
|
|
398
|
+
})
|
|
399
|
+
];
|
|
400
|
+
});
|
|
401
|
+
const resolve = (props = {}) => {
|
|
223
402
|
const result = {};
|
|
224
|
-
for (const [slot,
|
|
225
|
-
result[slot] = slotFn(props);
|
|
226
|
-
}
|
|
403
|
+
for (const [slot, fn] of slotFns) result[slot] = fn(props);
|
|
227
404
|
return result;
|
|
228
405
|
};
|
|
229
406
|
const raw = (props = {}) => {
|
|
230
407
|
const result = {};
|
|
231
|
-
for (const [slot,
|
|
232
|
-
result[slot] = slotFn.raw(props);
|
|
233
|
-
}
|
|
408
|
+
for (const [slot, fn] of slotFns) result[slot] = fn.raw(props);
|
|
234
409
|
return result;
|
|
235
410
|
};
|
|
236
|
-
return Object.assign(
|
|
411
|
+
return Object.assign(memoProps(resolve), {
|
|
237
412
|
__cva__: false,
|
|
238
413
|
raw,
|
|
239
414
|
config,
|
|
240
415
|
variantMap: Object.fromEntries(variantKeys.map((key) => [key, Object.keys(config.variants?.[key] ?? {})])),
|
|
241
416
|
variantKeys,
|
|
242
417
|
classNameMap: config.className ?? {},
|
|
243
|
-
getVariantProps(props)
|
|
244
|
-
|
|
245
|
-
for (const key in props) {
|
|
246
|
-
if (props[key] !== void 0) out[key] = props[key];
|
|
247
|
-
}
|
|
248
|
-
return out;
|
|
249
|
-
},
|
|
250
|
-
splitVariantProps(props) {
|
|
251
|
-
const rest = {};
|
|
252
|
-
const variantProps = {};
|
|
253
|
-
for (const key in props) {
|
|
254
|
-
if (variantKeySet.has(key)) variantProps[key] = props[key];
|
|
255
|
-
else rest[key] = props[key];
|
|
256
|
-
}
|
|
257
|
-
return [rest, variantProps];
|
|
258
|
-
}
|
|
418
|
+
getVariantProps: (props) => withDefaults(defaultVariants, props),
|
|
419
|
+
splitVariantProps: (props) => splitVariantProps(props, variantKeySet)
|
|
259
420
|
});
|
|
260
421
|
}
|
|
261
422
|
|
|
262
423
|
// src/runtime/internal/source.ts
|
|
263
|
-
var internalCssSource = 'var
|
|
424
|
+
var internalCssSource = 'var D="__PANDA_CX_SEPARATOR__";function w(n,r){let t=n.length;if(t>0&&n.charCodeAt(t-1)===33&&(t-=1),t===0)return null;let e=0,s=-1;for(let i=0;i<t;i++){let d=n.charCodeAt(i);d===91?e++:d===93?e--:d===58&&e===0&&(s=i)}let o=s+1,a=n.indexOf(r,o);if(a<o+1||a>=t)return null;let l=n.slice(o,a);return s===-1?l:`${n.slice(0,s)}:${l}`}function S(n,r){for(let t of n)if(t){if(Array.isArray(t)){S(t,r);continue}t!==""&&r.push(t)}}function H(n,r){let t=new Map,e=[],s=0;for(let a of r){let l=0;for(let i=0;i<=a.length;i++){if(i!==a.length&&a.charCodeAt(i)!==32)continue;if(i===l){l=i+1;continue}let d=a.slice(l,i);l=i+1;let u=w(d,n);if(u!==null)t.has(u)||e.push(u),t.set(u,d);else{let c=`__${s++}`;e.push(c),t.set(c,d)}}}if(e.length===0)return"";if(e.length===1)return t.get(e[0]);let o=t.get(e[0]);for(let a=1;a<e.length;a++)o+=` ${t.get(e[a])}`;return o}function P(n={}){let r=n.separator??D;return function(...e){if(e.length===1){let o=e[0];if(typeof o=="string")return o;if(!o)return""}let s=[];return S(e,s),s.length===0?"":s.length===1?s[0]:H(r,s)}}var y=P();function O(...n){return y(...n)}function R(n,r){let t={...n};for(let e in r)r[e]!==void 0&&(t[e]=r[e]);return t}function k(n,r){let t={},e={};for(let s in n)r.has(s)?e[s]=n[s]:t[s]=n[s];return[t,e]}function N(n){let r={};for(let t in n)r[t]=Object.keys(n[t]??{});return r}function T(n,r){for(let t in n){if(t==="css"||t==="className"||t==="classNames")continue;let e=n[t],s=r[t];if(Array.isArray(e)){if(!e.includes(s))return!1}else if(s!==e)return!1}return!0}function K(n,r,t){if(t==null)return;let e=n[r]?.[t];return typeof e=="string"&&e?e:void 0}function x(n){let r=new Map,t="",e,s=!1;return(o={})=>{let a="";for(let d in o){let u=o[d];u!==void 0&&(a+=`${d}:${String(u)}|`)}if(s&&a===t)return e;let l=r.get(a);if(l!==void 0)return t=a,e=l,s=!0,l;let i=n(o);return r.set(a,i),r.size>500&&r.delete(r.keys().next().value),t=a,e=i,s=!0,i}}function _(n){return n.length===0?"":n.length===1?n[0]:y(...n)}function L(n){if(!n)return!1;let r=Object.keys(n);return r.length===1&&r[0]==="true"&&typeof n.true=="string"}function $(n,r,t,e){if(!(e||r.length===0||r.length>12)){for(let s of r)if(!L(n[s]))return;for(let s in t){if(!r.includes(s))return;let o=t[s];if(o!==!0&&o!==!1&&o!=="true"&&o!=="false")return}return r}}function M(n){return n===!0||n==="true"}function E(n,r,t,e,s){let o=$(r,t,e,s);if(!o)return;let a=o.length,l=0;for(let u=0;u<a;u++)M(e[o[u]])&&(l|=1<<u);let i=new Array(1<<a),d=u=>{let c=[];n&&c.push(n);for(let f=0;f<a;f++)u&1<<f&&c.push(r[o[f]].true);return _(c)};return(u={})=>{let c=l;for(let f=0;f<a;f++){let g=u[o[f]];g!==void 0&&(M(g)?c|=1<<f:c&=~(1<<f))}return i[c]??=d(c)}}var X=4096;function F(n){let r=new Map;for(let t=0;t<n.length;t++){let e=n[t],s=t+1;if(r.set(e,s),e==="true")r.set(!0,s);else if(e==="false")r.set(!1,s);else{let o=Number(e);e!==""&&!Number.isNaN(o)&&r.set(o,s)}}return r}function j(n,r,t,e,s){if(s||t.length===0)return;let o=[],a=1;for(let u of t){let c=Object.keys(r[u]??{});if(c.length===0||(o.push({key:u,options:c,index:F(c),radix:c.length+1,stride:a}),a*=c.length+1,a>X))return}let l=0;for(let u in e){let c=o.find(g=>g.key===u);if(!c)return;let f=c.index.get(e[u]);if(f===void 0)return;l+=f*c.stride}let i=new Array(a),d=u=>{let c=[];n&&c.push(n);for(let f of o){let g=Math.floor(u/f.stride)%f.radix;if(g===0)continue;let p=r[f.key][f.options[g-1]];p&&c.push(p)}return _(c)};return(u={})=>{let c=l;for(let f=0;f<o.length;f++){let g=o[f],p=u[g.key];if(p===void 0)continue;let C=g.index.get(p)??0,m=Math.floor(c/g.stride)%g.radix;c+=(C-m)*g.stride}return i[c]??=d(c)}}function I(n,r){let t=[...n];for(let e of r)t.includes(e)||t.push(e);return t}function h(n){let r=n.base??"",t=n.variants??{},e=n.defaultVariants??{},s=n.compoundVariants??[],o=Object.keys(t),a=new Set(o),l=Object.keys(e).length>0,i=s.length>0,d=(f={})=>{let g=l?R(e,f):f,p=[];r&&p.push(r);for(let C of o){let m=K(t,C,g[C]);m&&p.push(m)}if(i)for(let C of s){if(!T(C,g))continue;let m=C.className??C.css;typeof m=="string"&&m&&p.push(m)}return _(p)},u=E(r,t,o,e,i)??j(r,t,o,e,i)??x(d),c=f=>{let g=f.config,p=g.variants??{},C={};for(let m of I(f.variantKeys,o)){let v={...t[m]},b=p[m]??{};for(let V in b){let A=v[V];v[V]=A?y(A,b[V]):b[V]}C[m]=v}return h({base:y(r,g.base),variants:C,defaultVariants:{...e,...g.defaultVariants},compoundVariants:[...s,...g.compoundVariants??[]]})};return Object.assign(u,{__cva__:!0,variantKeys:o,variantMap:N(t),raw:d,merge:c,config:n,getVariantProps:f=>R(e,f),splitVariantProps:f=>k(f,a)})}function q(n,r){if(!n?.length)return;let t=[];for(let e of n){let s={};for(let l in e)l==="css"||l==="className"||l==="classNames"||(s[l]=e[l]);let o=e.css;typeof o=="string"?s.css=o:o&&typeof o=="object"&&r in o&&(s.css=o[r]);let a=e.classNames?.[r]??e.className;a&&(s.className=a),(s.css||s.className)&&t.push(s)}return t.length?t:void 0}function B(n){let r=n.slots??Object.keys(n.base??{}),t=n.defaultVariants??{},e=Object.keys(n.variants??{}),s=new Set(e),o=r.map(i=>{let d=n.base?.[i];return n.className?.[i]&&(d=y(d,n.className[i])),[i,h({base:d,variants:n.variants,defaultVariants:n.defaultVariants,compoundVariants:q(n.compoundVariants,i)})]}),a=(i={})=>{let d={};for(let[u,c]of o)d[u]=c(i);return d},l=(i={})=>{let d={};for(let[u,c]of o)d[u]=c.raw(i);return d};return Object.assign(x(a),{__cva__:!1,raw:l,config:n,variantMap:Object.fromEntries(e.map(i=>[i,Object.keys(n.variants?.[i]??{})])),variantKeys:e,classNameMap:n.className??{},getVariantProps:i=>R(t,i),splitVariantProps:i=>k(i,s)})}export{O as css,h as cva,y as cx,B as sva};\n';
|
|
264
425
|
|
|
265
426
|
// src/runtime/internal/load.ts
|
|
266
427
|
var CX_SEPARATOR_PLACEHOLDER = "__PANDA_CX_SEPARATOR__";
|
package/dist/runtime/cx.js
CHANGED
|
@@ -93,8 +93,15 @@ function mergeClassStrings(separator, classes) {
|
|
|
93
93
|
function createCx(options = {}) {
|
|
94
94
|
const separator = options.separator ?? bakedSeparator;
|
|
95
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 "";
|
|
100
|
+
}
|
|
96
101
|
const flat = [];
|
|
97
102
|
flattenParts(parts, flat);
|
|
103
|
+
if (flat.length === 0) return "";
|
|
104
|
+
if (flat.length === 1) return flat[0];
|
|
98
105
|
return mergeClassStrings(separator, flat);
|
|
99
106
|
};
|
|
100
107
|
}
|
|
@@ -4,37 +4,46 @@ export { CxOptions, CxSeparator, PandaClassPart, createCx, cx, getMergeKey, spli
|
|
|
4
4
|
declare function css(...styles: string[]): string;
|
|
5
5
|
|
|
6
6
|
type VariantMap = Record<string, Record<string, string>>;
|
|
7
|
+
type VariantValue = string | number | boolean;
|
|
7
8
|
type CompoundVariant = Record<string, unknown> & {
|
|
8
9
|
css?: string;
|
|
9
10
|
className?: string;
|
|
10
11
|
};
|
|
12
|
+
|
|
11
13
|
interface StringCvaConfig {
|
|
12
14
|
base?: string;
|
|
13
15
|
variants?: VariantMap;
|
|
14
|
-
defaultVariants?: Record<string,
|
|
16
|
+
defaultVariants?: Record<string, VariantValue>;
|
|
15
17
|
compoundVariants?: CompoundVariant[];
|
|
16
18
|
}
|
|
19
|
+
/** The shape `merge` needs from the other recipe — `cva()`'s own return satisfies it. */
|
|
20
|
+
interface MergeableCva {
|
|
21
|
+
config: StringCvaConfig;
|
|
22
|
+
variantKeys: string[];
|
|
23
|
+
}
|
|
17
24
|
/** String-branch recipe factory for transformed source (TW-style cva). */
|
|
18
25
|
declare function cva(config: StringCvaConfig): ((props?: Record<string, unknown>) => string) & {
|
|
19
26
|
__cva__: true;
|
|
20
27
|
variantKeys: string[];
|
|
21
28
|
variantMap: Record<string, string[]>;
|
|
22
29
|
raw: (props?: Record<string, unknown>) => string;
|
|
30
|
+
merge: (other: MergeableCva) => ((props?: Record<string, unknown>) => string) & /*elided*/ any;
|
|
23
31
|
config: StringCvaConfig;
|
|
24
|
-
getVariantProps(props: Record<string, unknown>)
|
|
25
|
-
splitVariantProps(props: Record<string, unknown>)
|
|
32
|
+
getVariantProps: (props: Record<string, unknown>) => Record<string, unknown>;
|
|
33
|
+
splitVariantProps: (props: Record<string, unknown>) => [Record<string, unknown>, Record<string, unknown>];
|
|
26
34
|
};
|
|
27
35
|
|
|
36
|
+
type SvaCompound = Record<string, unknown> & {
|
|
37
|
+
css?: Record<string, string> | string;
|
|
38
|
+
className?: string;
|
|
39
|
+
classNames?: Record<string, string>;
|
|
40
|
+
};
|
|
28
41
|
type SvaConfig = {
|
|
29
42
|
slots?: string[];
|
|
30
43
|
base?: Record<string, string>;
|
|
31
44
|
variants?: StringCvaConfig['variants'];
|
|
32
45
|
defaultVariants?: StringCvaConfig['defaultVariants'];
|
|
33
|
-
compoundVariants?:
|
|
34
|
-
css?: Record<string, string> | string;
|
|
35
|
-
className?: string;
|
|
36
|
-
classNames?: Record<string, string>;
|
|
37
|
-
}>;
|
|
46
|
+
compoundVariants?: SvaCompound[];
|
|
38
47
|
className?: Record<string, string>;
|
|
39
48
|
};
|
|
40
49
|
/** String-branch slot recipe factory for transformed source. */
|
|
@@ -47,8 +56,8 @@ declare function sva(config: SvaConfig): ((props?: Record<string, unknown>) => R
|
|
|
47
56
|
};
|
|
48
57
|
variantKeys: string[];
|
|
49
58
|
classNameMap: Record<string, string>;
|
|
50
|
-
getVariantProps(props: Record<string, unknown>)
|
|
51
|
-
splitVariantProps(props: Record<string, unknown>)
|
|
59
|
+
getVariantProps: (props: Record<string, unknown>) => Record<string, unknown>;
|
|
60
|
+
splitVariantProps: (props: Record<string, unknown>) => [Record<string, unknown>, Record<string, unknown>];
|
|
52
61
|
};
|
|
53
62
|
|
|
54
63
|
export { type StringCvaConfig, css, cva, sva };
|
package/dist/runtime/internal.js
CHANGED
|
@@ -93,8 +93,15 @@ function mergeClassStrings(separator, classes) {
|
|
|
93
93
|
function createCx(options = {}) {
|
|
94
94
|
const separator = options.separator ?? bakedSeparator;
|
|
95
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 "";
|
|
100
|
+
}
|
|
96
101
|
const flat = [];
|
|
97
102
|
flattenParts(parts, flat);
|
|
103
|
+
if (flat.length === 0) return "";
|
|
104
|
+
if (flat.length === 1) return flat[0];
|
|
98
105
|
return mergeClassStrings(separator, flat);
|
|
99
106
|
};
|
|
100
107
|
}
|
|
@@ -105,7 +112,7 @@ function css(...styles) {
|
|
|
105
112
|
return cx(...styles);
|
|
106
113
|
}
|
|
107
114
|
|
|
108
|
-
// src/runtime/internal/
|
|
115
|
+
// src/runtime/internal/shared.ts
|
|
109
116
|
function withDefaults(defaults, props) {
|
|
110
117
|
const out = { ...defaults };
|
|
111
118
|
for (const key in props) {
|
|
@@ -113,6 +120,20 @@ function withDefaults(defaults, props) {
|
|
|
113
120
|
}
|
|
114
121
|
return out;
|
|
115
122
|
}
|
|
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
|
+
}
|
|
116
137
|
function compoundMatches(compound, variants) {
|
|
117
138
|
for (const key in compound) {
|
|
118
139
|
if (key === "css" || key === "className" || key === "classNames") continue;
|
|
@@ -126,10 +147,160 @@ function compoundMatches(compound, variants) {
|
|
|
126
147
|
}
|
|
127
148
|
return true;
|
|
128
149
|
}
|
|
129
|
-
function
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return
|
|
150
|
+
function variantClass(variants, key, value) {
|
|
151
|
+
if (value == null) return void 0;
|
|
152
|
+
const cls = variants[key]?.[value];
|
|
153
|
+
return typeof cls === "string" && cls ? cls : void 0;
|
|
154
|
+
}
|
|
155
|
+
function memoProps(resolve) {
|
|
156
|
+
const cache = /* @__PURE__ */ new Map();
|
|
157
|
+
let lastKey = "";
|
|
158
|
+
let lastValue;
|
|
159
|
+
let hasLast = false;
|
|
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;
|
|
173
|
+
}
|
|
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
|
+
}
|
|
203
|
+
return keys;
|
|
204
|
+
}
|
|
205
|
+
function selectsTrue(value) {
|
|
206
|
+
return value === true || value === "true";
|
|
207
|
+
}
|
|
208
|
+
function booleanBitset(base, variants, keys, defaults, hasCompounds) {
|
|
209
|
+
const boolKeys = booleanKeys(variants, keys, defaults, hasCompounds);
|
|
210
|
+
if (!boolKeys) return void 0;
|
|
211
|
+
const n = boolKeys.length;
|
|
212
|
+
let defaultMask = 0;
|
|
213
|
+
for (let i = 0; i < n; i++) {
|
|
214
|
+
if (selectsTrue(defaults[boolKeys[i]])) defaultMask |= 1 << i;
|
|
215
|
+
}
|
|
216
|
+
const table = new Array(1 << n);
|
|
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
|
+
};
|
|
235
|
+
}
|
|
236
|
+
var MAX_VARIANT_STATES = 4096;
|
|
237
|
+
function optionIndex(options) {
|
|
238
|
+
const index = /* @__PURE__ */ new Map();
|
|
239
|
+
for (let i = 0; i < options.length; i++) {
|
|
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
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return index;
|
|
251
|
+
}
|
|
252
|
+
function variantTable(base, variants, keys, defaults, hasCompounds) {
|
|
253
|
+
if (hasCompounds || keys.length === 0) return void 0;
|
|
254
|
+
const slots = [];
|
|
255
|
+
let states = 1;
|
|
256
|
+
for (const key of keys) {
|
|
257
|
+
const options = Object.keys(variants[key] ?? {});
|
|
258
|
+
if (options.length === 0) return void 0;
|
|
259
|
+
slots.push({ key, options, index: optionIndex(options), radix: options.length + 1, stride: states });
|
|
260
|
+
states *= options.length + 1;
|
|
261
|
+
if (states > MAX_VARIANT_STATES) return void 0;
|
|
262
|
+
}
|
|
263
|
+
let defaultState = 0;
|
|
264
|
+
for (const key in defaults) {
|
|
265
|
+
const slot = slots.find((candidate) => candidate.key === key);
|
|
266
|
+
if (!slot) return void 0;
|
|
267
|
+
const chosen = slot.index.get(defaults[key]);
|
|
268
|
+
if (chosen === void 0) return void 0;
|
|
269
|
+
defaultState += chosen * slot.stride;
|
|
270
|
+
}
|
|
271
|
+
const table = new Array(states);
|
|
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);
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// src/runtime/internal/cva.ts
|
|
298
|
+
function unionKeys(other, own) {
|
|
299
|
+
const keys = [...other];
|
|
300
|
+
for (const key of own) {
|
|
301
|
+
if (!keys.includes(key)) keys.push(key);
|
|
302
|
+
}
|
|
303
|
+
return keys;
|
|
133
304
|
}
|
|
134
305
|
function cva(config) {
|
|
135
306
|
const base = config.base ?? "";
|
|
@@ -138,49 +309,63 @@ function cva(config) {
|
|
|
138
309
|
const compoundVariants = config.compoundVariants ?? [];
|
|
139
310
|
const variantKeys = Object.keys(variants);
|
|
140
311
|
const variantKeySet = new Set(variantKeys);
|
|
312
|
+
const hasDefaults = Object.keys(defaultVariants).length > 0;
|
|
313
|
+
const hasCompounds = compoundVariants.length > 0;
|
|
141
314
|
const resolve = (props = {}) => {
|
|
142
|
-
const computed = withDefaults(defaultVariants, props);
|
|
315
|
+
const computed = hasDefaults ? withDefaults(defaultVariants, props) : props;
|
|
143
316
|
const parts = [];
|
|
144
317
|
if (base) parts.push(base);
|
|
145
318
|
for (const key of variantKeys) {
|
|
146
|
-
const
|
|
147
|
-
if (
|
|
148
|
-
|
|
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);
|
|
149
327
|
}
|
|
150
328
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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;
|
|
155
344
|
}
|
|
156
|
-
return
|
|
345
|
+
return cva({
|
|
346
|
+
base: cx(base, override.base),
|
|
347
|
+
variants: mergedVariants,
|
|
348
|
+
defaultVariants: { ...defaultVariants, ...override.defaultVariants },
|
|
349
|
+
compoundVariants: [...compoundVariants, ...override.compoundVariants ?? []]
|
|
350
|
+
});
|
|
157
351
|
};
|
|
158
|
-
const cvaFn = (props = {}) => resolve(props);
|
|
159
352
|
return Object.assign(cvaFn, {
|
|
160
353
|
__cva__: true,
|
|
161
354
|
variantKeys,
|
|
162
355
|
variantMap: toVariantMap(variants),
|
|
163
356
|
raw: resolve,
|
|
357
|
+
merge,
|
|
164
358
|
config,
|
|
165
|
-
getVariantProps(props)
|
|
166
|
-
|
|
167
|
-
},
|
|
168
|
-
splitVariantProps(props) {
|
|
169
|
-
const rest = {};
|
|
170
|
-
const variantProps = {};
|
|
171
|
-
for (const key in props) {
|
|
172
|
-
if (variantKeySet.has(key)) variantProps[key] = props[key];
|
|
173
|
-
else rest[key] = props[key];
|
|
174
|
-
}
|
|
175
|
-
return [rest, variantProps];
|
|
176
|
-
}
|
|
359
|
+
getVariantProps: (props) => withDefaults(defaultVariants, props),
|
|
360
|
+
splitVariantProps: (props) => splitVariantProps(props, variantKeySet)
|
|
177
361
|
});
|
|
178
362
|
}
|
|
179
363
|
|
|
180
364
|
// src/runtime/internal/sva.ts
|
|
181
|
-
function
|
|
182
|
-
if (!
|
|
183
|
-
|
|
365
|
+
function compoundsForSlot(compounds, slot) {
|
|
366
|
+
if (!compounds?.length) return void 0;
|
|
367
|
+
const out = [];
|
|
368
|
+
for (const compound of compounds) {
|
|
184
369
|
const next = {};
|
|
185
370
|
for (const key in compound) {
|
|
186
371
|
if (key === "css" || key === "className" || key === "classNames") continue;
|
|
@@ -191,71 +376,47 @@ function slotCompoundVariants(compoundVariants, slot) {
|
|
|
191
376
|
else if (css2 && typeof css2 === "object" && slot in css2) next.css = css2[slot];
|
|
192
377
|
const className = compound.classNames?.[slot] ?? compound.className;
|
|
193
378
|
if (className) next.className = className;
|
|
194
|
-
|
|
195
|
-
}).filter((compound) => compound.css || compound.className);
|
|
196
|
-
}
|
|
197
|
-
function getSlotRecipes(config) {
|
|
198
|
-
const slots = config.slots ?? Object.keys(config.base ?? {});
|
|
199
|
-
const recipes = {};
|
|
200
|
-
for (const slot of slots) {
|
|
201
|
-
recipes[slot] = {
|
|
202
|
-
base: config.base?.[slot],
|
|
203
|
-
variants: config.variants,
|
|
204
|
-
defaultVariants: config.defaultVariants,
|
|
205
|
-
compoundVariants: slotCompoundVariants(config.compoundVariants, slot)
|
|
206
|
-
};
|
|
207
|
-
if (config.className?.[slot]) {
|
|
208
|
-
recipes[slot] = {
|
|
209
|
-
...recipes[slot],
|
|
210
|
-
base: cx(recipes[slot]?.base, config.className[slot])
|
|
211
|
-
};
|
|
212
|
-
}
|
|
379
|
+
if (next.css || next.className) out.push(next);
|
|
213
380
|
}
|
|
214
|
-
return
|
|
381
|
+
return out.length ? out : void 0;
|
|
215
382
|
}
|
|
216
383
|
function sva(config) {
|
|
217
|
-
const
|
|
218
|
-
const slots = Object.entries(slotRecipes).map(([slot, recipe]) => [slot, cva(recipe)]);
|
|
384
|
+
const slots = config.slots ?? Object.keys(config.base ?? {});
|
|
219
385
|
const defaultVariants = config.defaultVariants ?? {};
|
|
220
386
|
const variantKeys = Object.keys(config.variants ?? {});
|
|
221
387
|
const variantKeySet = new Set(variantKeys);
|
|
222
|
-
const
|
|
388
|
+
const slotFns = slots.map((slot) => {
|
|
389
|
+
let base = config.base?.[slot];
|
|
390
|
+
if (config.className?.[slot]) base = cx(base, config.className[slot]);
|
|
391
|
+
return [
|
|
392
|
+
slot,
|
|
393
|
+
cva({
|
|
394
|
+
base,
|
|
395
|
+
variants: config.variants,
|
|
396
|
+
defaultVariants: config.defaultVariants,
|
|
397
|
+
compoundVariants: compoundsForSlot(config.compoundVariants, slot)
|
|
398
|
+
})
|
|
399
|
+
];
|
|
400
|
+
});
|
|
401
|
+
const resolve = (props = {}) => {
|
|
223
402
|
const result = {};
|
|
224
|
-
for (const [slot,
|
|
225
|
-
result[slot] = slotFn(props);
|
|
226
|
-
}
|
|
403
|
+
for (const [slot, fn] of slotFns) result[slot] = fn(props);
|
|
227
404
|
return result;
|
|
228
405
|
};
|
|
229
406
|
const raw = (props = {}) => {
|
|
230
407
|
const result = {};
|
|
231
|
-
for (const [slot,
|
|
232
|
-
result[slot] = slotFn.raw(props);
|
|
233
|
-
}
|
|
408
|
+
for (const [slot, fn] of slotFns) result[slot] = fn.raw(props);
|
|
234
409
|
return result;
|
|
235
410
|
};
|
|
236
|
-
return Object.assign(
|
|
411
|
+
return Object.assign(memoProps(resolve), {
|
|
237
412
|
__cva__: false,
|
|
238
413
|
raw,
|
|
239
414
|
config,
|
|
240
415
|
variantMap: Object.fromEntries(variantKeys.map((key) => [key, Object.keys(config.variants?.[key] ?? {})])),
|
|
241
416
|
variantKeys,
|
|
242
417
|
classNameMap: config.className ?? {},
|
|
243
|
-
getVariantProps(props)
|
|
244
|
-
|
|
245
|
-
for (const key in props) {
|
|
246
|
-
if (props[key] !== void 0) out[key] = props[key];
|
|
247
|
-
}
|
|
248
|
-
return out;
|
|
249
|
-
},
|
|
250
|
-
splitVariantProps(props) {
|
|
251
|
-
const rest = {};
|
|
252
|
-
const variantProps = {};
|
|
253
|
-
for (const key in props) {
|
|
254
|
-
if (variantKeySet.has(key)) variantProps[key] = props[key];
|
|
255
|
-
else rest[key] = props[key];
|
|
256
|
-
}
|
|
257
|
-
return [rest, variantProps];
|
|
258
|
-
}
|
|
418
|
+
getVariantProps: (props) => withDefaults(defaultVariants, props),
|
|
419
|
+
splitVariantProps: (props) => splitVariantProps(props, variantKeySet)
|
|
259
420
|
});
|
|
260
421
|
}
|
|
261
422
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var D="__PANDA_CX_SEPARATOR__";function w(n,r){let t=n.length;if(t>0&&n.charCodeAt(t-1)===33&&(t-=1),t===0)return null;let e=0,s=-1;for(let i=0;i<t;i++){let d=n.charCodeAt(i);d===91?e++:d===93?e--:d===58&&e===0&&(s=i)}let o=s+1,a=n.indexOf(r,o);if(a<o+1||a>=t)return null;let l=n.slice(o,a);return s===-1?l:`${n.slice(0,s)}:${l}`}function S(n,r){for(let t of n)if(t){if(Array.isArray(t)){S(t,r);continue}t!==""&&r.push(t)}}function H(n,r){let t=new Map,e=[],s=0;for(let a of r){let l=0;for(let i=0;i<=a.length;i++){if(i!==a.length&&a.charCodeAt(i)!==32)continue;if(i===l){l=i+1;continue}let d=a.slice(l,i);l=i+1;let u=w(d,n);if(u!==null)t.has(u)||e.push(u),t.set(u,d);else{let c=`__${s++}`;e.push(c),t.set(c,d)}}}if(e.length===0)return"";if(e.length===1)return t.get(e[0]);let o=t.get(e[0]);for(let a=1;a<e.length;a++)o+=` ${t.get(e[a])}`;return o}function P(n={}){let r=n.separator??D;return function(...e){if(e.length===1){let o=e[0];if(typeof o=="string")return o;if(!o)return""}let s=[];return S(e,s),s.length===0?"":s.length===1?s[0]:H(r,s)}}var y=P();function O(...n){return y(...n)}function R(n,r){let t={...n};for(let e in r)r[e]!==void 0&&(t[e]=r[e]);return t}function k(n,r){let t={},e={};for(let s in n)r.has(s)?e[s]=n[s]:t[s]=n[s];return[t,e]}function N(n){let r={};for(let t in n)r[t]=Object.keys(n[t]??{});return r}function T(n,r){for(let t in n){if(t==="css"||t==="className"||t==="classNames")continue;let e=n[t],s=r[t];if(Array.isArray(e)){if(!e.includes(s))return!1}else if(s!==e)return!1}return!0}function K(n,r,t){if(t==null)return;let e=n[r]?.[t];return typeof e=="string"&&e?e:void 0}function x(n){let r=new Map,t="",e,s=!1;return(o={})=>{let a="";for(let d in o){let u=o[d];u!==void 0&&(a+=`${d}:${String(u)}|`)}if(s&&a===t)return e;let l=r.get(a);if(l!==void 0)return t=a,e=l,s=!0,l;let i=n(o);return r.set(a,i),r.size>500&&r.delete(r.keys().next().value),t=a,e=i,s=!0,i}}function _(n){return n.length===0?"":n.length===1?n[0]:y(...n)}function L(n){if(!n)return!1;let r=Object.keys(n);return r.length===1&&r[0]==="true"&&typeof n.true=="string"}function $(n,r,t,e){if(!(e||r.length===0||r.length>12)){for(let s of r)if(!L(n[s]))return;for(let s in t){if(!r.includes(s))return;let o=t[s];if(o!==!0&&o!==!1&&o!=="true"&&o!=="false")return}return r}}function M(n){return n===!0||n==="true"}function E(n,r,t,e,s){let o=$(r,t,e,s);if(!o)return;let a=o.length,l=0;for(let u=0;u<a;u++)M(e[o[u]])&&(l|=1<<u);let i=new Array(1<<a),d=u=>{let c=[];n&&c.push(n);for(let f=0;f<a;f++)u&1<<f&&c.push(r[o[f]].true);return _(c)};return(u={})=>{let c=l;for(let f=0;f<a;f++){let g=u[o[f]];g!==void 0&&(M(g)?c|=1<<f:c&=~(1<<f))}return i[c]??=d(c)}}var X=4096;function F(n){let r=new Map;for(let t=0;t<n.length;t++){let e=n[t],s=t+1;if(r.set(e,s),e==="true")r.set(!0,s);else if(e==="false")r.set(!1,s);else{let o=Number(e);e!==""&&!Number.isNaN(o)&&r.set(o,s)}}return r}function j(n,r,t,e,s){if(s||t.length===0)return;let o=[],a=1;for(let u of t){let c=Object.keys(r[u]??{});if(c.length===0||(o.push({key:u,options:c,index:F(c),radix:c.length+1,stride:a}),a*=c.length+1,a>X))return}let l=0;for(let u in e){let c=o.find(g=>g.key===u);if(!c)return;let f=c.index.get(e[u]);if(f===void 0)return;l+=f*c.stride}let i=new Array(a),d=u=>{let c=[];n&&c.push(n);for(let f of o){let g=Math.floor(u/f.stride)%f.radix;if(g===0)continue;let p=r[f.key][f.options[g-1]];p&&c.push(p)}return _(c)};return(u={})=>{let c=l;for(let f=0;f<o.length;f++){let g=o[f],p=u[g.key];if(p===void 0)continue;let C=g.index.get(p)??0,m=Math.floor(c/g.stride)%g.radix;c+=(C-m)*g.stride}return i[c]??=d(c)}}function I(n,r){let t=[...n];for(let e of r)t.includes(e)||t.push(e);return t}function h(n){let r=n.base??"",t=n.variants??{},e=n.defaultVariants??{},s=n.compoundVariants??[],o=Object.keys(t),a=new Set(o),l=Object.keys(e).length>0,i=s.length>0,d=(f={})=>{let g=l?R(e,f):f,p=[];r&&p.push(r);for(let C of o){let m=K(t,C,g[C]);m&&p.push(m)}if(i)for(let C of s){if(!T(C,g))continue;let m=C.className??C.css;typeof m=="string"&&m&&p.push(m)}return _(p)},u=E(r,t,o,e,i)??j(r,t,o,e,i)??x(d),c=f=>{let g=f.config,p=g.variants??{},C={};for(let m of I(f.variantKeys,o)){let v={...t[m]},b=p[m]??{};for(let V in b){let A=v[V];v[V]=A?y(A,b[V]):b[V]}C[m]=v}return h({base:y(r,g.base),variants:C,defaultVariants:{...e,...g.defaultVariants},compoundVariants:[...s,...g.compoundVariants??[]]})};return Object.assign(u,{__cva__:!0,variantKeys:o,variantMap:N(t),raw:d,merge:c,config:n,getVariantProps:f=>R(e,f),splitVariantProps:f=>k(f,a)})}function q(n,r){if(!n?.length)return;let t=[];for(let e of n){let s={};for(let l in e)l==="css"||l==="className"||l==="classNames"||(s[l]=e[l]);let o=e.css;typeof o=="string"?s.css=o:o&&typeof o=="object"&&r in o&&(s.css=o[r]);let a=e.classNames?.[r]??e.className;a&&(s.className=a),(s.css||s.className)&&t.push(s)}return t.length?t:void 0}function B(n){let r=n.slots??Object.keys(n.base??{}),t=n.defaultVariants??{},e=Object.keys(n.variants??{}),s=new Set(e),o=r.map(i=>{let d=n.base?.[i];return n.className?.[i]&&(d=y(d,n.className[i])),[i,h({base:d,variants:n.variants,defaultVariants:n.defaultVariants,compoundVariants:q(n.compoundVariants,i)})]}),a=(i={})=>{let d={};for(let[u,c]of o)d[u]=c(i);return d},l=(i={})=>{let d={};for(let[u,c]of o)d[u]=c.raw(i);return d};return Object.assign(x(a),{__cva__:!1,raw:l,config:n,variantMap:Object.fromEntries(e.map(i=>[i,Object.keys(n.variants?.[i]??{})])),variantKeys:e,classNameMap:n.className??{},getVariantProps:i=>R(t,i),splitVariantProps:i=>k(i,s)})}export{O as css,h as cva,y as cx,B as sva};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/transformer",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.12",
|
|
4
4
|
"description": "Source transformer facade for Panda CSS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"unplugin": "^2.3.10",
|
|
38
|
-
"@pandacss/compiler": "2.0.0-beta.
|
|
39
|
-
"@pandacss/compiler-shared": "2.0.0-beta.
|
|
38
|
+
"@pandacss/compiler": "2.0.0-beta.12",
|
|
39
|
+
"@pandacss/compiler-shared": "2.0.0-beta.12"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"vite": ">=6.0.0",
|