@barocss/kit 0.0.2 → 0.4.0
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/README.md +4 -4
- package/dist/index.d.ts +135 -19
- package/dist/index.js +502 -272
- package/dist/index.js.map +1 -1
- package/dist/theme/default.d.ts +7 -2
- package/package.json +10 -2
package/dist/index.js
CHANGED
|
@@ -34,16 +34,203 @@ function property(name, initialValue, syntax, source) {
|
|
|
34
34
|
}
|
|
35
35
|
return atRule("property", name, nodes, source);
|
|
36
36
|
}
|
|
37
|
+
class AstCache {
|
|
38
|
+
constructor() {
|
|
39
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
40
|
+
this.maxSize = 1e3;
|
|
41
|
+
}
|
|
42
|
+
// Prevent memory leaks
|
|
43
|
+
set(key, ast) {
|
|
44
|
+
if (this.cache.size >= this.maxSize) {
|
|
45
|
+
const firstKey = this.cache.keys().next().value;
|
|
46
|
+
if (firstKey) {
|
|
47
|
+
this.cache.delete(firstKey);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
this.cache.set(key, ast);
|
|
51
|
+
}
|
|
52
|
+
get(key) {
|
|
53
|
+
return this.cache.get(key);
|
|
54
|
+
}
|
|
55
|
+
has(key) {
|
|
56
|
+
return this.cache.has(key);
|
|
57
|
+
}
|
|
58
|
+
clear() {
|
|
59
|
+
this.cache.clear();
|
|
60
|
+
}
|
|
61
|
+
getStats() {
|
|
62
|
+
return {
|
|
63
|
+
size: this.cache.size,
|
|
64
|
+
maxSize: this.maxSize,
|
|
65
|
+
hitRate: this.cache.size / this.maxSize
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const astCache = new AstCache();
|
|
70
|
+
class ParseResultCache {
|
|
71
|
+
constructor() {
|
|
72
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
73
|
+
this.maxSize = 2e3;
|
|
74
|
+
}
|
|
75
|
+
// Prevent memory leaks
|
|
76
|
+
set(key, result) {
|
|
77
|
+
if (this.cache.size >= this.maxSize) {
|
|
78
|
+
const firstKey = this.cache.keys().next().value;
|
|
79
|
+
if (firstKey) {
|
|
80
|
+
this.cache.delete(firstKey);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
this.cache.set(key, result);
|
|
84
|
+
}
|
|
85
|
+
get(key) {
|
|
86
|
+
return this.cache.get(key);
|
|
87
|
+
}
|
|
88
|
+
has(key) {
|
|
89
|
+
return this.cache.has(key);
|
|
90
|
+
}
|
|
91
|
+
clear() {
|
|
92
|
+
this.cache.clear();
|
|
93
|
+
}
|
|
94
|
+
getStats() {
|
|
95
|
+
return {
|
|
96
|
+
size: this.cache.size,
|
|
97
|
+
maxSize: this.maxSize,
|
|
98
|
+
hitRate: this.cache.size / this.maxSize
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const parseResultCache = new ParseResultCache();
|
|
103
|
+
class UtilityCache {
|
|
104
|
+
constructor() {
|
|
105
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
106
|
+
this.maxSize = 1e3;
|
|
107
|
+
}
|
|
108
|
+
// Prevent memory leaks
|
|
109
|
+
set(key, value) {
|
|
110
|
+
if (this.cache.size >= this.maxSize) {
|
|
111
|
+
const firstKey = this.cache.keys().next().value;
|
|
112
|
+
if (firstKey) {
|
|
113
|
+
this.cache.delete(firstKey);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
this.cache.set(key, value);
|
|
117
|
+
}
|
|
118
|
+
get(key) {
|
|
119
|
+
return this.cache.get(key);
|
|
120
|
+
}
|
|
121
|
+
has(key) {
|
|
122
|
+
return this.cache.has(key);
|
|
123
|
+
}
|
|
124
|
+
clear() {
|
|
125
|
+
this.cache.clear();
|
|
126
|
+
}
|
|
127
|
+
getStats() {
|
|
128
|
+
return {
|
|
129
|
+
size: this.cache.size,
|
|
130
|
+
maxSize: this.maxSize,
|
|
131
|
+
hitRate: this.cache.size / this.maxSize
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const utilityCache = new UtilityCache();
|
|
136
|
+
let resetContextCaches;
|
|
137
|
+
function setContextCacheReset(reset) {
|
|
138
|
+
resetContextCaches = reset;
|
|
139
|
+
}
|
|
140
|
+
function clearAllCaches() {
|
|
141
|
+
astCache.clear();
|
|
142
|
+
parseResultCache.clear();
|
|
143
|
+
utilityCache.clear();
|
|
144
|
+
resetContextCaches?.();
|
|
145
|
+
console.log("[clearAllCaches] All caches cleared");
|
|
146
|
+
}
|
|
147
|
+
class WeakCache {
|
|
148
|
+
constructor() {
|
|
149
|
+
this.cache = /* @__PURE__ */ new WeakMap();
|
|
150
|
+
this.keyMap = /* @__PURE__ */ new Map();
|
|
151
|
+
this.maxSize = 1e3;
|
|
152
|
+
}
|
|
153
|
+
set(key, value) {
|
|
154
|
+
if (this.keyMap.size >= this.maxSize) {
|
|
155
|
+
const firstKey = this.keyMap.keys().next().value;
|
|
156
|
+
if (firstKey) {
|
|
157
|
+
const obj2 = this.keyMap.get(firstKey);
|
|
158
|
+
if (obj2) {
|
|
159
|
+
this.cache.delete(obj2);
|
|
160
|
+
}
|
|
161
|
+
this.keyMap.delete(firstKey);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const obj = { key };
|
|
165
|
+
this.cache.set(obj, value);
|
|
166
|
+
this.keyMap.set(key, obj);
|
|
167
|
+
}
|
|
168
|
+
get(key) {
|
|
169
|
+
const obj = this.keyMap.get(key);
|
|
170
|
+
if (obj) {
|
|
171
|
+
return this.cache.get(obj);
|
|
172
|
+
}
|
|
173
|
+
return void 0;
|
|
174
|
+
}
|
|
175
|
+
has(key) {
|
|
176
|
+
return this.keyMap.has(key);
|
|
177
|
+
}
|
|
178
|
+
clear() {
|
|
179
|
+
this.keyMap.clear();
|
|
180
|
+
}
|
|
181
|
+
getStats() {
|
|
182
|
+
return {
|
|
183
|
+
size: this.keyMap.size,
|
|
184
|
+
maxSize: this.maxSize,
|
|
185
|
+
hitRate: this.keyMap.size / this.maxSize
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const states = /* @__PURE__ */ new WeakMap();
|
|
190
|
+
let cacheGeneration = 0;
|
|
191
|
+
setContextCacheReset(() => {
|
|
192
|
+
cacheGeneration += 1;
|
|
193
|
+
});
|
|
194
|
+
function initializeContextState(ctx, utilities, modifiers) {
|
|
195
|
+
states.set(ctx, {
|
|
196
|
+
utilities: [...utilities],
|
|
197
|
+
modifiers: [...modifiers],
|
|
198
|
+
astCache: new AstCache(),
|
|
199
|
+
parseResultCache: new ParseResultCache(),
|
|
200
|
+
utilityCache: new UtilityCache(),
|
|
201
|
+
failures: /* @__PURE__ */ new Set(),
|
|
202
|
+
cacheGeneration
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
function getContextState(ctx) {
|
|
206
|
+
const state = states.get(ctx);
|
|
207
|
+
if (state && state.cacheGeneration !== cacheGeneration) {
|
|
208
|
+
clearContextCaches(ctx);
|
|
209
|
+
state.cacheGeneration = cacheGeneration;
|
|
210
|
+
}
|
|
211
|
+
return state;
|
|
212
|
+
}
|
|
213
|
+
function clearContextCaches(ctx) {
|
|
214
|
+
const state = states.get(ctx);
|
|
215
|
+
if (!state) return;
|
|
216
|
+
state.astCache.clear();
|
|
217
|
+
state.parseResultCache.clear();
|
|
218
|
+
state.utilityCache.clear();
|
|
219
|
+
state.failures.clear();
|
|
220
|
+
}
|
|
37
221
|
const utilityRegistry = [];
|
|
38
|
-
function registerUtility(util) {
|
|
39
|
-
|
|
222
|
+
function registerUtility(util, ctx) {
|
|
223
|
+
const state = ctx && getContextState(ctx);
|
|
224
|
+
if (ctx && !state) throw new Error("Utility registration requires a context from createContext");
|
|
225
|
+
(state?.utilities || utilityRegistry).push(util);
|
|
226
|
+
if (ctx) clearContextCaches(ctx);
|
|
40
227
|
}
|
|
41
|
-
function getUtility() {
|
|
42
|
-
return utilityRegistry;
|
|
228
|
+
function getUtility(ctx) {
|
|
229
|
+
return ctx && getContextState(ctx)?.utilities || utilityRegistry;
|
|
43
230
|
}
|
|
44
231
|
const modifierRegistry = [];
|
|
45
|
-
function staticModifier(name, selectors, options = {}) {
|
|
46
|
-
|
|
232
|
+
function staticModifier(name, selectors, options = {}, ctx) {
|
|
233
|
+
registerModifier({
|
|
47
234
|
match: (mod) => mod === name,
|
|
48
235
|
modifySelector: ({ ..._rest }) => {
|
|
49
236
|
return selectors.map((sel) => ({
|
|
@@ -52,13 +239,19 @@ function staticModifier(name, selectors, options = {}) {
|
|
|
52
239
|
}));
|
|
53
240
|
},
|
|
54
241
|
...options
|
|
55
|
-
});
|
|
242
|
+
}, ctx);
|
|
243
|
+
}
|
|
244
|
+
function functionalModifier(match, modifySelector, wrap, options = {}, ctx) {
|
|
245
|
+
registerModifier({ match, modifySelector, wrap, ...options }, ctx);
|
|
56
246
|
}
|
|
57
|
-
function
|
|
58
|
-
|
|
247
|
+
function registerModifier(modifier, ctx) {
|
|
248
|
+
const state = ctx && getContextState(ctx);
|
|
249
|
+
if (ctx && !state) throw new Error("Modifier registration requires a context from createContext");
|
|
250
|
+
(state?.modifiers || modifierRegistry).push(modifier);
|
|
251
|
+
if (ctx) clearContextCaches(ctx);
|
|
59
252
|
}
|
|
60
|
-
function getModifier() {
|
|
61
|
-
return modifierRegistry;
|
|
253
|
+
function getModifier(ctx) {
|
|
254
|
+
return ctx && getContextState(ctx)?.modifiers || modifierRegistry;
|
|
62
255
|
}
|
|
63
256
|
const ESCAPE_REGEX = /[^A-Za-z0-9_-]/g;
|
|
64
257
|
function escapeClassName(className) {
|
|
@@ -97,7 +290,7 @@ function escapeClassName(className) {
|
|
|
97
290
|
return "\\" + c;
|
|
98
291
|
});
|
|
99
292
|
}
|
|
100
|
-
function staticUtility(name, decls, opts) {
|
|
293
|
+
function staticUtility(name, decls, opts, ctx) {
|
|
101
294
|
registerUtility({
|
|
102
295
|
name,
|
|
103
296
|
match: (className) => {
|
|
@@ -124,13 +317,13 @@ function staticUtility(name, decls, opts) {
|
|
|
124
317
|
description: opts?.description,
|
|
125
318
|
category: opts?.category,
|
|
126
319
|
priority: opts?.priority
|
|
127
|
-
});
|
|
320
|
+
}, ctx);
|
|
128
321
|
}
|
|
129
|
-
function functionalUtility(opts) {
|
|
322
|
+
function functionalUtility(opts, ctx) {
|
|
130
323
|
registerUtility({
|
|
131
324
|
name: opts.name,
|
|
132
325
|
match: (className) => className.startsWith(opts.name + "-"),
|
|
133
|
-
handler: (value,
|
|
326
|
+
handler: (value, ctx2, token, _options) => {
|
|
134
327
|
let finalValue = value;
|
|
135
328
|
const parsedUtility = token;
|
|
136
329
|
const extra = {
|
|
@@ -146,7 +339,7 @@ function functionalUtility(opts) {
|
|
|
146
339
|
if (opts.supportsArbitrary && parsedUtility.arbitrary) {
|
|
147
340
|
const processedValue = finalValue.replace(/_/g, " ");
|
|
148
341
|
if (opts.handle) {
|
|
149
|
-
const result = opts.handle(processedValue,
|
|
342
|
+
const result = opts.handle(processedValue, ctx2, token, extra);
|
|
150
343
|
if (result) return result;
|
|
151
344
|
}
|
|
152
345
|
if (opts.prop) {
|
|
@@ -156,12 +349,12 @@ function functionalUtility(opts) {
|
|
|
156
349
|
}
|
|
157
350
|
if (opts.supportsCustomProperty && parsedUtility.customProperty) {
|
|
158
351
|
if (opts.handleCustomProperty) {
|
|
159
|
-
const result = opts.handleCustomProperty(finalValue,
|
|
352
|
+
const result = opts.handleCustomProperty(finalValue, ctx2, token, extra);
|
|
160
353
|
return result;
|
|
161
354
|
}
|
|
162
355
|
const customValue = `var(${finalValue})`;
|
|
163
356
|
if (opts.handle) {
|
|
164
|
-
const result = opts.handle(customValue,
|
|
357
|
+
const result = opts.handle(customValue, ctx2, token, extra);
|
|
165
358
|
if (result) return result;
|
|
166
359
|
}
|
|
167
360
|
if (opts.prop) {
|
|
@@ -170,12 +363,12 @@ function functionalUtility(opts) {
|
|
|
170
363
|
return [];
|
|
171
364
|
}
|
|
172
365
|
let themeValue;
|
|
173
|
-
if (opts.themeKey &&
|
|
174
|
-
themeValue =
|
|
366
|
+
if (opts.themeKey && ctx2.theme) {
|
|
367
|
+
themeValue = ctx2.theme(opts.themeKey, finalValue);
|
|
175
368
|
}
|
|
176
|
-
if (!themeValue && opts.themeKeys &&
|
|
369
|
+
if (!themeValue && opts.themeKeys && ctx2.theme) {
|
|
177
370
|
for (const key of opts.themeKeys) {
|
|
178
|
-
themeValue =
|
|
371
|
+
themeValue = ctx2.theme(key, finalValue);
|
|
179
372
|
if (themeValue !== void 0) break;
|
|
180
373
|
}
|
|
181
374
|
}
|
|
@@ -186,7 +379,7 @@ function functionalUtility(opts) {
|
|
|
186
379
|
return [decl(opts.prop, finalValue)];
|
|
187
380
|
}
|
|
188
381
|
if (opts.handle) {
|
|
189
|
-
const result = opts.handle(finalValue,
|
|
382
|
+
const result = opts.handle(finalValue, ctx2, token, extra);
|
|
190
383
|
if (result) return result;
|
|
191
384
|
}
|
|
192
385
|
return [];
|
|
@@ -195,16 +388,16 @@ function functionalUtility(opts) {
|
|
|
195
388
|
finalValue = value;
|
|
196
389
|
}
|
|
197
390
|
if (parsedUtility.negative && opts.supportsNegative && opts.handleNegativeBareValue) {
|
|
198
|
-
const bare = opts.handleNegativeBareValue({ value: String(finalValue).replace(/^-/, ""), ctx, token, extra });
|
|
391
|
+
const bare = opts.handleNegativeBareValue({ value: String(finalValue).replace(/^-/, ""), ctx: ctx2, token, extra });
|
|
199
392
|
if (bare == null) return [];
|
|
200
393
|
finalValue = bare;
|
|
201
394
|
} else if (opts.handleBareValue) {
|
|
202
|
-
const bare = opts.handleBareValue({ value: finalValue, ctx, token, extra });
|
|
395
|
+
const bare = opts.handleBareValue({ value: finalValue, ctx: ctx2, token, extra });
|
|
203
396
|
if (bare == null) return [];
|
|
204
397
|
finalValue = bare;
|
|
205
398
|
}
|
|
206
399
|
if (opts.handle) {
|
|
207
|
-
const result = opts.handle(finalValue,
|
|
400
|
+
const result = opts.handle(finalValue, ctx2, token, extra);
|
|
208
401
|
if (result) return result;
|
|
209
402
|
}
|
|
210
403
|
if (opts.prop) {
|
|
@@ -215,7 +408,7 @@ function functionalUtility(opts) {
|
|
|
215
408
|
description: opts.description,
|
|
216
409
|
category: opts.category,
|
|
217
410
|
priority: opts.priority
|
|
218
|
-
});
|
|
411
|
+
}, ctx);
|
|
219
412
|
}
|
|
220
413
|
function tokenize(className) {
|
|
221
414
|
const tokens = [];
|
|
@@ -252,159 +445,13 @@ function tokenize(className) {
|
|
|
252
445
|
}
|
|
253
446
|
return tokens;
|
|
254
447
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
// Prevent memory leaks
|
|
261
|
-
set(key, ast) {
|
|
262
|
-
if (this.cache.size >= this.maxSize) {
|
|
263
|
-
const firstKey = this.cache.keys().next().value;
|
|
264
|
-
if (firstKey) {
|
|
265
|
-
this.cache.delete(firstKey);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
this.cache.set(key, ast);
|
|
269
|
-
}
|
|
270
|
-
get(key) {
|
|
271
|
-
return this.cache.get(key);
|
|
272
|
-
}
|
|
273
|
-
has(key) {
|
|
274
|
-
return this.cache.has(key);
|
|
275
|
-
}
|
|
276
|
-
clear() {
|
|
277
|
-
this.cache.clear();
|
|
278
|
-
}
|
|
279
|
-
getStats() {
|
|
280
|
-
return {
|
|
281
|
-
size: this.cache.size,
|
|
282
|
-
maxSize: this.maxSize,
|
|
283
|
-
hitRate: this.cache.size / this.maxSize
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
const astCache = new AstCache();
|
|
288
|
-
class ParseResultCache {
|
|
289
|
-
constructor() {
|
|
290
|
-
this.cache = /* @__PURE__ */ new Map();
|
|
291
|
-
this.maxSize = 2e3;
|
|
292
|
-
}
|
|
293
|
-
// Prevent memory leaks
|
|
294
|
-
set(key, result) {
|
|
295
|
-
if (this.cache.size >= this.maxSize) {
|
|
296
|
-
const firstKey = this.cache.keys().next().value;
|
|
297
|
-
if (firstKey) {
|
|
298
|
-
this.cache.delete(firstKey);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
this.cache.set(key, result);
|
|
302
|
-
}
|
|
303
|
-
get(key) {
|
|
304
|
-
return this.cache.get(key);
|
|
305
|
-
}
|
|
306
|
-
has(key) {
|
|
307
|
-
return this.cache.has(key);
|
|
308
|
-
}
|
|
309
|
-
clear() {
|
|
310
|
-
this.cache.clear();
|
|
311
|
-
}
|
|
312
|
-
getStats() {
|
|
313
|
-
return {
|
|
314
|
-
size: this.cache.size,
|
|
315
|
-
maxSize: this.maxSize,
|
|
316
|
-
hitRate: this.cache.size / this.maxSize
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
const parseResultCache = new ParseResultCache();
|
|
321
|
-
class UtilityCache {
|
|
322
|
-
constructor() {
|
|
323
|
-
this.cache = /* @__PURE__ */ new Map();
|
|
324
|
-
this.maxSize = 1e3;
|
|
325
|
-
}
|
|
326
|
-
// Prevent memory leaks
|
|
327
|
-
set(key, value) {
|
|
328
|
-
if (this.cache.size >= this.maxSize) {
|
|
329
|
-
const firstKey = this.cache.keys().next().value;
|
|
330
|
-
if (firstKey) {
|
|
331
|
-
this.cache.delete(firstKey);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
this.cache.set(key, value);
|
|
335
|
-
}
|
|
336
|
-
get(key) {
|
|
337
|
-
return this.cache.get(key);
|
|
338
|
-
}
|
|
339
|
-
has(key) {
|
|
340
|
-
return this.cache.has(key);
|
|
341
|
-
}
|
|
342
|
-
clear() {
|
|
343
|
-
this.cache.clear();
|
|
344
|
-
}
|
|
345
|
-
getStats() {
|
|
346
|
-
return {
|
|
347
|
-
size: this.cache.size,
|
|
348
|
-
maxSize: this.maxSize,
|
|
349
|
-
hitRate: this.cache.size / this.maxSize
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
const utilityCache = new UtilityCache();
|
|
354
|
-
function clearAllCaches() {
|
|
355
|
-
astCache.clear();
|
|
356
|
-
parseResultCache.clear();
|
|
357
|
-
utilityCache.clear();
|
|
358
|
-
console.log("[clearAllCaches] All caches cleared");
|
|
359
|
-
}
|
|
360
|
-
class WeakCache {
|
|
361
|
-
constructor() {
|
|
362
|
-
this.cache = /* @__PURE__ */ new WeakMap();
|
|
363
|
-
this.keyMap = /* @__PURE__ */ new Map();
|
|
364
|
-
this.maxSize = 1e3;
|
|
448
|
+
function isUtilityPrefix(str, ctx) {
|
|
449
|
+
const cache = ctx && getContextState(ctx)?.utilityCache || utilityCache;
|
|
450
|
+
if (cache.has(str)) {
|
|
451
|
+
return cache.get(str);
|
|
365
452
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
const firstKey = this.keyMap.keys().next().value;
|
|
369
|
-
if (firstKey) {
|
|
370
|
-
const obj2 = this.keyMap.get(firstKey);
|
|
371
|
-
if (obj2) {
|
|
372
|
-
this.cache.delete(obj2);
|
|
373
|
-
}
|
|
374
|
-
this.keyMap.delete(firstKey);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
const obj = { key };
|
|
378
|
-
this.cache.set(obj, value);
|
|
379
|
-
this.keyMap.set(key, obj);
|
|
380
|
-
}
|
|
381
|
-
get(key) {
|
|
382
|
-
const obj = this.keyMap.get(key);
|
|
383
|
-
if (obj) {
|
|
384
|
-
return this.cache.get(obj);
|
|
385
|
-
}
|
|
386
|
-
return void 0;
|
|
387
|
-
}
|
|
388
|
-
has(key) {
|
|
389
|
-
return this.keyMap.has(key);
|
|
390
|
-
}
|
|
391
|
-
clear() {
|
|
392
|
-
this.keyMap.clear();
|
|
393
|
-
}
|
|
394
|
-
getStats() {
|
|
395
|
-
return {
|
|
396
|
-
size: this.keyMap.size,
|
|
397
|
-
maxSize: this.maxSize,
|
|
398
|
-
hitRate: this.keyMap.size / this.maxSize
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
function isUtilityPrefix(str) {
|
|
403
|
-
if (utilityCache.has(str)) {
|
|
404
|
-
return utilityCache.get(str);
|
|
405
|
-
}
|
|
406
|
-
const utilities = getUtility();
|
|
407
|
-
const modifiers = getModifier();
|
|
453
|
+
const utilities = getUtility(ctx);
|
|
454
|
+
const modifiers = getModifier(ctx);
|
|
408
455
|
const candidateUtilities = utilities.filter((util) => {
|
|
409
456
|
const prefix = util.name;
|
|
410
457
|
return str.startsWith(prefix + "-") || str === prefix || str.startsWith(prefix);
|
|
@@ -416,12 +463,13 @@ function isUtilityPrefix(str) {
|
|
|
416
463
|
});
|
|
417
464
|
const isModifier = candidateModifiers.some((mod) => mod.match(str, {}));
|
|
418
465
|
const result = isUtility && !isModifier;
|
|
419
|
-
|
|
466
|
+
cache.set(str, result);
|
|
420
467
|
return result;
|
|
421
468
|
}
|
|
422
|
-
function parseClassName(className) {
|
|
423
|
-
|
|
424
|
-
|
|
469
|
+
function parseClassName(className, ctx) {
|
|
470
|
+
const cache = ctx && getContextState(ctx)?.parseResultCache || parseResultCache;
|
|
471
|
+
if (cache.has(className)) {
|
|
472
|
+
return cache.get(className);
|
|
425
473
|
}
|
|
426
474
|
let important = false;
|
|
427
475
|
let realClassName = className;
|
|
@@ -430,38 +478,38 @@ function parseClassName(className) {
|
|
|
430
478
|
realClassName = className.slice(1);
|
|
431
479
|
}
|
|
432
480
|
const tokens = tokenize(realClassName);
|
|
433
|
-
const result = parseTokens(tokens);
|
|
481
|
+
const result = parseTokens(tokens, ctx);
|
|
434
482
|
if (result.utility) {
|
|
435
483
|
result.utility.important = important;
|
|
436
484
|
}
|
|
437
|
-
|
|
485
|
+
cache.set(className, result);
|
|
438
486
|
return result;
|
|
439
487
|
}
|
|
440
|
-
function parseTokens(tokens) {
|
|
488
|
+
function parseTokens(tokens, ctx) {
|
|
441
489
|
const modifiers = [];
|
|
442
490
|
let utility = null;
|
|
443
491
|
if (tokens.length === 0) {
|
|
444
492
|
return { modifiers, utility: null };
|
|
445
493
|
}
|
|
446
494
|
if (tokens.length === 1) {
|
|
447
|
-
utility = parseUtility(tokens[0].value);
|
|
495
|
+
utility = parseUtility(tokens[0].value, ctx);
|
|
448
496
|
} else if (tokens.length === 2) {
|
|
449
497
|
const firstToken = tokens[0];
|
|
450
498
|
const secondToken = tokens[1];
|
|
451
|
-
const isFirstUtility = isUtilityPrefix(firstToken.value);
|
|
499
|
+
const isFirstUtility = isUtilityPrefix(firstToken.value, ctx);
|
|
452
500
|
if (isFirstUtility) {
|
|
453
|
-
utility = parseUtility(firstToken.value);
|
|
501
|
+
utility = parseUtility(firstToken.value, ctx);
|
|
454
502
|
const parsed = parseModifier(secondToken.value);
|
|
455
503
|
if (parsed) modifiers.push(parsed);
|
|
456
504
|
} else {
|
|
457
505
|
const parsed = parseModifier(firstToken.value);
|
|
458
506
|
if (parsed) modifiers.push(parsed);
|
|
459
|
-
utility = parseUtility(secondToken.value);
|
|
507
|
+
utility = parseUtility(secondToken.value, ctx);
|
|
460
508
|
}
|
|
461
509
|
} else {
|
|
462
|
-
const isFirstUtility = isUtilityPrefix(tokens[0].value);
|
|
510
|
+
const isFirstUtility = isUtilityPrefix(tokens[0].value, ctx);
|
|
463
511
|
if (isFirstUtility) {
|
|
464
|
-
utility = parseUtility(tokens[0].value);
|
|
512
|
+
utility = parseUtility(tokens[0].value, ctx);
|
|
465
513
|
for (let i = 1; i < tokens.length; i++) {
|
|
466
514
|
const parsed = parseModifier(tokens[i].value);
|
|
467
515
|
if (parsed) modifiers.push(parsed);
|
|
@@ -471,7 +519,7 @@ function parseTokens(tokens) {
|
|
|
471
519
|
const parsed = parseModifier(tokens[i].value);
|
|
472
520
|
if (parsed) modifiers.push(parsed);
|
|
473
521
|
}
|
|
474
|
-
utility = parseUtility(tokens[tokens.length - 1].value);
|
|
522
|
+
utility = parseUtility(tokens[tokens.length - 1].value, ctx);
|
|
475
523
|
}
|
|
476
524
|
}
|
|
477
525
|
return { modifiers, utility };
|
|
@@ -491,7 +539,7 @@ function parseModifier(value) {
|
|
|
491
539
|
function nameSort(a, b) {
|
|
492
540
|
return b.name.length - a.name.length;
|
|
493
541
|
}
|
|
494
|
-
function parseUtility(value) {
|
|
542
|
+
function parseUtility(value, ctx) {
|
|
495
543
|
let prefix = "";
|
|
496
544
|
let utilityValue = "";
|
|
497
545
|
let arbitrary = false;
|
|
@@ -518,8 +566,7 @@ function parseUtility(value) {
|
|
|
518
566
|
utilityValue = utilityValue.replace(/\)$/, "");
|
|
519
567
|
customProperty = true;
|
|
520
568
|
} else {
|
|
521
|
-
const
|
|
522
|
-
const sortedUtilities = utilities.sort(nameSort);
|
|
569
|
+
const sortedUtilities = [...getUtility(ctx)].sort(nameSort);
|
|
523
570
|
let matchedUtility = sortedUtilities.find((p) => value === p.name);
|
|
524
571
|
if (matchedUtility) {
|
|
525
572
|
prefix = matchedUtility.name;
|
|
@@ -730,7 +777,7 @@ ${node.nodes.map((node2) => {
|
|
|
730
777
|
}).join("\n");
|
|
731
778
|
return result;
|
|
732
779
|
}
|
|
733
|
-
const failureCache = /* @__PURE__ */ new
|
|
780
|
+
const failureCache = /* @__PURE__ */ new Set();
|
|
734
781
|
function collectDeclPaths(nodes = [], path = []) {
|
|
735
782
|
let result = [];
|
|
736
783
|
for (const node of nodes) {
|
|
@@ -894,32 +941,29 @@ function extractAtRootNodes(nodes, parent, atRootNodes = []) {
|
|
|
894
941
|
}
|
|
895
942
|
}
|
|
896
943
|
function parseClassToAst(fullClassName, ctx) {
|
|
897
|
-
|
|
944
|
+
const state = getContextState(ctx);
|
|
945
|
+
const failures = state?.failures || failureCache;
|
|
946
|
+
const cache = state?.astCache || astCache;
|
|
947
|
+
if (failures.has(fullClassName)) {
|
|
898
948
|
return [];
|
|
899
949
|
}
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
darkModeSelector: ctx.config("darkModeSelector"),
|
|
903
|
-
theme: ctx.theme
|
|
904
|
-
});
|
|
905
|
-
const cacheKey = `${fullClassName}:${contextHash}`;
|
|
906
|
-
if (astCache.has(cacheKey)) {
|
|
907
|
-
return astCache.get(cacheKey);
|
|
950
|
+
if (cache.has(fullClassName)) {
|
|
951
|
+
return cache.get(fullClassName);
|
|
908
952
|
}
|
|
909
|
-
const { modifiers, utility } = parseClassName(fullClassName);
|
|
953
|
+
const { modifiers, utility } = parseClassName(fullClassName, ctx);
|
|
910
954
|
if (!utility) {
|
|
911
955
|
console.warn(`[BAROCSS] Invalid class name format: "${fullClassName}"`);
|
|
912
|
-
|
|
956
|
+
failures.add(fullClassName);
|
|
913
957
|
return [];
|
|
914
958
|
}
|
|
915
|
-
const utilReg = getUtility().find((u) => {
|
|
959
|
+
const utilReg = getUtility(ctx).find((u) => {
|
|
916
960
|
const fullClassName2 = utility.value ? `${utility.prefix}-${utility.value}` : utility.prefix;
|
|
917
961
|
return u.match(fullClassName2);
|
|
918
962
|
});
|
|
919
963
|
if (!utilReg) {
|
|
920
964
|
const utilityName = utility.value ? `${utility.prefix}-${utility.value}` : utility.prefix;
|
|
921
965
|
console.warn(`[BAROCSS] Unknown utility class: "${utilityName}" in "${fullClassName}"`);
|
|
922
|
-
|
|
966
|
+
failures.add(fullClassName);
|
|
923
967
|
return [];
|
|
924
968
|
}
|
|
925
969
|
let value = utility.value;
|
|
@@ -929,10 +973,11 @@ function parseClassToAst(fullClassName, ctx) {
|
|
|
929
973
|
const selector = "&";
|
|
930
974
|
for (let i = 0; i < modifiers.length; i++) {
|
|
931
975
|
const variant = modifiers[i];
|
|
932
|
-
const plugin = getModifier().find((p) => p.match(variant.type, ctx));
|
|
976
|
+
const plugin = getModifier(ctx).find((p) => p.match(variant.type, ctx));
|
|
933
977
|
if (!plugin) {
|
|
934
978
|
console.warn(`[BAROCSS] Unknown variant: "${variant.type}" in "${fullClassName}"`);
|
|
935
|
-
|
|
979
|
+
failures.add(fullClassName);
|
|
980
|
+
return [];
|
|
936
981
|
}
|
|
937
982
|
if (plugin.wrap) {
|
|
938
983
|
const items = plugin.wrap(variant, ctx);
|
|
@@ -940,7 +985,6 @@ function parseClassToAst(fullClassName, ctx) {
|
|
|
940
985
|
type: "wrap",
|
|
941
986
|
items
|
|
942
987
|
});
|
|
943
|
-
continue;
|
|
944
988
|
}
|
|
945
989
|
if (plugin.modifySelector) {
|
|
946
990
|
const result = plugin.modifySelector({
|
|
@@ -951,9 +995,10 @@ function parseClassToAst(fullClassName, ctx) {
|
|
|
951
995
|
variantChain: modifiers,
|
|
952
996
|
index: i
|
|
953
997
|
});
|
|
998
|
+
if (plugin.wrap && (result === "&" || typeof result === "object" && !Array.isArray(result) && result.selector === "&" || Array.isArray(result) && result.length === 1 && result[0].selector === "&")) continue;
|
|
954
999
|
if (typeof result === "string" && result.includes("&")) {
|
|
955
1000
|
wrappers.push({ type: "rule", selector: result });
|
|
956
|
-
} else if (typeof result === "object" && result.selector) {
|
|
1001
|
+
} else if (typeof result === "object" && !Array.isArray(result) && result.selector) {
|
|
957
1002
|
const wrappingType = result.wrappingType || "rule";
|
|
958
1003
|
wrappers.push({
|
|
959
1004
|
type: wrappingType,
|
|
@@ -977,10 +1022,7 @@ function parseClassToAst(fullClassName, ctx) {
|
|
|
977
1022
|
for (let i = wrappers.length - 1; i >= 0; i--) {
|
|
978
1023
|
const wrap = wrappers[i];
|
|
979
1024
|
if (wrap.type === "wrap") {
|
|
980
|
-
ast = wrap.items.map((item) =>
|
|
981
|
-
...item,
|
|
982
|
-
nodes: Array.isArray(ast) ? ast : [ast]
|
|
983
|
-
}));
|
|
1025
|
+
ast = wrap.items.map((item) => item.type === "rule" || item.type === "style-rule" || item.type === "at-rule" || item.type === "at-root" ? { ...item, nodes: [...item.nodes || [], ...ast] } : item);
|
|
984
1026
|
} else if (wrap.type === "style-rule") {
|
|
985
1027
|
ast = [
|
|
986
1028
|
{
|
|
@@ -1014,12 +1056,19 @@ function parseClassToAst(fullClassName, ctx) {
|
|
|
1014
1056
|
const atRootNodes = [];
|
|
1015
1057
|
extractAtRootNodes(ast, void 0, atRootNodes);
|
|
1016
1058
|
ast = [...atRootNodes, ...ast].filter(Boolean);
|
|
1017
|
-
|
|
1059
|
+
cache.set(fullClassName, ast);
|
|
1018
1060
|
return ast;
|
|
1019
1061
|
}
|
|
1020
|
-
function clearAstCache() {
|
|
1021
|
-
|
|
1022
|
-
|
|
1062
|
+
function clearAstCache(ctx) {
|
|
1063
|
+
if (ctx) {
|
|
1064
|
+
clearContextCaches(ctx);
|
|
1065
|
+
} else {
|
|
1066
|
+
clearAllCaches();
|
|
1067
|
+
failureCache.clear();
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
function getAstCacheStats(ctx) {
|
|
1071
|
+
return (ctx && getContextState(ctx)?.astCache || astCache).getStats();
|
|
1023
1072
|
}
|
|
1024
1073
|
function generateCss(classList, ctx, opts) {
|
|
1025
1074
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -1033,7 +1082,7 @@ function generateCss(classList, ctx, opts) {
|
|
|
1033
1082
|
return true;
|
|
1034
1083
|
}).map((cls) => {
|
|
1035
1084
|
const ast = parseClassToAst(cls, ctx);
|
|
1036
|
-
const parsedResult = parseResultCache.get(cls);
|
|
1085
|
+
const parsedResult = (getContextState(ctx)?.parseResultCache || parseResultCache).get(cls);
|
|
1037
1086
|
const cleanAst = optimizeAst(ast);
|
|
1038
1087
|
cleanAst.forEach((node) => {
|
|
1039
1088
|
if (node.type === "at-root") {
|
|
@@ -1041,24 +1090,28 @@ function generateCss(classList, ctx, opts) {
|
|
|
1041
1090
|
}
|
|
1042
1091
|
});
|
|
1043
1092
|
const hasStyleRule = cleanAst.some((node) => node.type === "style-rule");
|
|
1044
|
-
const css = astToCss(cleanAst, hasStyleRule ? void 0 : cls, {
|
|
1093
|
+
const css = astToCss(cleanAst.filter((node) => node.type !== "at-root"), hasStyleRule ? void 0 : cls, {
|
|
1045
1094
|
minify: opts?.minify,
|
|
1046
1095
|
important: parsedResult?.utility?.important ?? false
|
|
1047
1096
|
});
|
|
1048
|
-
const
|
|
1049
|
-
const result = `${rootCss ? `:root,:host {${rootCss}}` : ""}${css}`;
|
|
1097
|
+
const result = css;
|
|
1050
1098
|
if (!result || result.trim() === "") {
|
|
1051
1099
|
console.warn("[generateCss] Empty CSS generated for class:", {
|
|
1052
1100
|
class: cls,
|
|
1053
1101
|
ast: cleanAst,
|
|
1054
1102
|
hasStyleRule,
|
|
1055
1103
|
css,
|
|
1056
|
-
rootCss,
|
|
1057
1104
|
result
|
|
1058
1105
|
});
|
|
1059
1106
|
}
|
|
1060
1107
|
return result;
|
|
1061
1108
|
}).join(opts?.minify ? "" : "\n");
|
|
1109
|
+
const rootRules = [...new Set(allAtRootNodes.filter((node) => node.type === "at-rule").map((node) => rootToCss([node])))];
|
|
1110
|
+
const rootDeclarations = [...new Set(allAtRootNodes.filter((node) => node.type === "decl").map((node) => rootToCss([node])))];
|
|
1111
|
+
const rootCss = [
|
|
1112
|
+
...rootRules,
|
|
1113
|
+
...rootDeclarations.length ? [`:root,:host {${rootDeclarations.join("\n")}}`] : []
|
|
1114
|
+
].join(opts?.minify ? "" : "\n");
|
|
1062
1115
|
if (allAtRootNodes.length > 0) {
|
|
1063
1116
|
console.log("[generateCss] All collected atRoot nodes:", allAtRootNodes);
|
|
1064
1117
|
}
|
|
@@ -1069,14 +1122,10 @@ function generateCss(classList, ctx, opts) {
|
|
|
1069
1122
|
allAtRootNodes
|
|
1070
1123
|
});
|
|
1071
1124
|
}
|
|
1072
|
-
return results
|
|
1125
|
+
return `${rootCss}${rootCss && results ? opts?.minify ? "" : "\n" : ""}${results}`;
|
|
1073
1126
|
}
|
|
1074
1127
|
function generateCssRules(classList, ctx, opts) {
|
|
1075
1128
|
const seen = /* @__PURE__ */ new Set();
|
|
1076
|
-
const options = {
|
|
1077
|
-
minify: opts?.minify,
|
|
1078
|
-
dedup: opts?.dedup
|
|
1079
|
-
};
|
|
1080
1129
|
return classList.split(/\s+/).filter((cls) => {
|
|
1081
1130
|
if (!cls) return false;
|
|
1082
1131
|
if (opts?.dedup) {
|
|
@@ -1086,6 +1135,11 @@ function generateCssRules(classList, ctx, opts) {
|
|
|
1086
1135
|
return true;
|
|
1087
1136
|
}).map((cls) => {
|
|
1088
1137
|
const ast = parseClassToAst(cls, ctx);
|
|
1138
|
+
const parsedResult = (getContextState(ctx)?.parseResultCache || parseResultCache).get(cls);
|
|
1139
|
+
const options = {
|
|
1140
|
+
minify: opts?.minify,
|
|
1141
|
+
important: parsedResult?.utility?.important ?? false
|
|
1142
|
+
};
|
|
1089
1143
|
const cleanAst = optimizeAst(ast);
|
|
1090
1144
|
const allAtRootNodes = cleanAst.filter(
|
|
1091
1145
|
(node) => node.type === "at-root" && !node.source
|
|
@@ -1199,7 +1253,7 @@ class IncrementalParser {
|
|
|
1199
1253
|
return null;
|
|
1200
1254
|
}
|
|
1201
1255
|
try {
|
|
1202
|
-
const parseResult = parseClassName(className);
|
|
1256
|
+
const parseResult = parseClassName(className, this.ctx);
|
|
1203
1257
|
if (!parseResult.utility) {
|
|
1204
1258
|
return null;
|
|
1205
1259
|
}
|
|
@@ -1332,7 +1386,7 @@ class IncrementalParser {
|
|
|
1332
1386
|
processedClasses: this.processedClasses.size,
|
|
1333
1387
|
pendingClasses: this.pendingClasses.size,
|
|
1334
1388
|
cacheStats: {
|
|
1335
|
-
ast: astCache.getStats(),
|
|
1389
|
+
ast: (getContextState(this.ctx)?.astCache || astCache).getStats(),
|
|
1336
1390
|
css: {}
|
|
1337
1391
|
// No CSS cache, so return empty object
|
|
1338
1392
|
}
|
|
@@ -1391,18 +1445,6 @@ class IncrementalParser {
|
|
|
1391
1445
|
return Array.from(this.processedClasses);
|
|
1392
1446
|
}
|
|
1393
1447
|
}
|
|
1394
|
-
function normalizePrefix(prefix) {
|
|
1395
|
-
let p = prefix.trim();
|
|
1396
|
-
if (!p.startsWith("--")) p = `--${p}`;
|
|
1397
|
-
if (!p.endsWith("-")) p = `${p}-`;
|
|
1398
|
-
return p;
|
|
1399
|
-
}
|
|
1400
|
-
function setVarPrefix(prefix) {
|
|
1401
|
-
if (typeof prefix !== "string" || prefix.trim() === "") {
|
|
1402
|
-
return;
|
|
1403
|
-
}
|
|
1404
|
-
normalizePrefix(prefix);
|
|
1405
|
-
}
|
|
1406
1448
|
function escapeKey(key) {
|
|
1407
1449
|
return key.replace(".", "\\.");
|
|
1408
1450
|
}
|
|
@@ -2310,7 +2352,7 @@ function deepMerge(base, override) {
|
|
|
2310
2352
|
}
|
|
2311
2353
|
return result;
|
|
2312
2354
|
}
|
|
2313
|
-
|
|
2355
|
+
const themeLookupsInProgress = /* @__PURE__ */ new WeakMap();
|
|
2314
2356
|
function themeGetter(themeObj, ...path) {
|
|
2315
2357
|
const theme = (...args) => themeGetter(themeObj, ...args);
|
|
2316
2358
|
let keys = [];
|
|
@@ -2330,26 +2372,28 @@ function themeGetter(themeObj, ...path) {
|
|
|
2330
2372
|
}
|
|
2331
2373
|
}
|
|
2332
2374
|
if (keys.length === 0) return void 0;
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
let value = themeObj[keys[0]];
|
|
2338
|
-
if (typeof value === "function") {
|
|
2339
|
-
value = value(theme);
|
|
2340
|
-
}
|
|
2341
|
-
for (let i = 1; i < keys.length; i++) {
|
|
2342
|
-
if (value == null) {
|
|
2343
|
-
staticInProgress?.delete(pathKey);
|
|
2344
|
-
return void 0;
|
|
2345
|
-
}
|
|
2346
|
-
value = value[keys[i]];
|
|
2375
|
+
let inProgress = themeLookupsInProgress.get(themeObj);
|
|
2376
|
+
if (!inProgress) {
|
|
2377
|
+
inProgress = /* @__PURE__ */ new Set();
|
|
2378
|
+
themeLookupsInProgress.set(themeObj, inProgress);
|
|
2347
2379
|
}
|
|
2348
|
-
|
|
2349
|
-
if (
|
|
2350
|
-
|
|
2380
|
+
const pathKey = keys.join(".");
|
|
2381
|
+
if (inProgress.has(pathKey)) return void 0;
|
|
2382
|
+
inProgress.add(pathKey);
|
|
2383
|
+
try {
|
|
2384
|
+
let value = themeObj[keys[0]];
|
|
2385
|
+
if (typeof value === "function") {
|
|
2386
|
+
value = value(theme);
|
|
2387
|
+
}
|
|
2388
|
+
for (let i = 1; i < keys.length; i++) {
|
|
2389
|
+
if (value == null) return void 0;
|
|
2390
|
+
value = value[keys[i]];
|
|
2391
|
+
}
|
|
2392
|
+
if (typeof value === "function") return void 0;
|
|
2393
|
+
return value;
|
|
2394
|
+
} finally {
|
|
2395
|
+
inProgress.delete(pathKey);
|
|
2351
2396
|
}
|
|
2352
|
-
return value;
|
|
2353
2397
|
}
|
|
2354
2398
|
function configGetter(config, ...path) {
|
|
2355
2399
|
let keys = [];
|
|
@@ -2397,11 +2441,7 @@ function createContext(configObj) {
|
|
|
2397
2441
|
],
|
|
2398
2442
|
...configObj
|
|
2399
2443
|
};
|
|
2400
|
-
setVarPrefix(configWithDefaults.cssVarPrefix || "--bcss-");
|
|
2401
2444
|
const themeObj = resolveTheme(configWithDefaults);
|
|
2402
|
-
if (configObj.clearCacheOnContextChange !== false) {
|
|
2403
|
-
clearAllCaches();
|
|
2404
|
-
}
|
|
2405
2445
|
const ctx = {
|
|
2406
2446
|
hasPreset: (category, preset) => {
|
|
2407
2447
|
const result = hasPreset(themeObj, category, preset);
|
|
@@ -2435,13 +2475,182 @@ function createContext(configObj) {
|
|
|
2435
2475
|
...values
|
|
2436
2476
|
};
|
|
2437
2477
|
} else ;
|
|
2478
|
+
clearContextCaches(ctx);
|
|
2438
2479
|
},
|
|
2439
2480
|
getPreflightCSS: (level = true) => {
|
|
2440
2481
|
return getPreflightCSS(level);
|
|
2441
2482
|
}
|
|
2442
2483
|
};
|
|
2484
|
+
initializeContextState(ctx, getUtility(), getModifier());
|
|
2443
2485
|
return ctx;
|
|
2444
2486
|
}
|
|
2487
|
+
function jsonToAst(input, ctx) {
|
|
2488
|
+
let utilReg = getUtility(ctx).find((u) => u.name === input.utility.name);
|
|
2489
|
+
if (input.utility.value && !input.utility.arbitrary && !input.utility.customProperty) {
|
|
2490
|
+
const fullName = `${input.utility.name}-${input.utility.value}`;
|
|
2491
|
+
const exactMatch = getUtility(ctx).find((u) => u.name === fullName);
|
|
2492
|
+
if (exactMatch) {
|
|
2493
|
+
utilReg = exactMatch;
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2496
|
+
if (!utilReg) {
|
|
2497
|
+
console.warn(`[jsonToAst] Unknown utility: "${input.utility.name}"`);
|
|
2498
|
+
return [];
|
|
2499
|
+
}
|
|
2500
|
+
const parsedUtility = {
|
|
2501
|
+
prefix: input.utility.name,
|
|
2502
|
+
value: input.utility.value,
|
|
2503
|
+
arbitrary: input.utility.arbitrary,
|
|
2504
|
+
negative: input.utility.negative,
|
|
2505
|
+
opacity: input.utility.opacity,
|
|
2506
|
+
important: input.utility.important,
|
|
2507
|
+
customProperty: input.utility.customProperty,
|
|
2508
|
+
category: utilReg.category,
|
|
2509
|
+
priority: utilReg.priority
|
|
2510
|
+
};
|
|
2511
|
+
let value = input.utility.value;
|
|
2512
|
+
if (input.utility.negative && value) {
|
|
2513
|
+
value = "-" + value;
|
|
2514
|
+
}
|
|
2515
|
+
let ast = utilReg.handler(value || "", ctx, parsedUtility, utilReg) || [];
|
|
2516
|
+
if (input.variants && input.variants.length > 0) {
|
|
2517
|
+
const wrappers = [];
|
|
2518
|
+
const selector = "&";
|
|
2519
|
+
for (let i = input.variants.length - 1; i >= 0; i--) {
|
|
2520
|
+
const variantInput = input.variants[i];
|
|
2521
|
+
const variantName = typeof variantInput === "string" ? variantInput : variantInput.name;
|
|
2522
|
+
const variantValue = typeof variantInput === "string" ? void 0 : variantInput.value;
|
|
2523
|
+
const variantArbitrary = typeof variantInput === "string" ? false : variantInput.arbitrary;
|
|
2524
|
+
const parsedModifier = {
|
|
2525
|
+
type: variantName,
|
|
2526
|
+
value: variantValue,
|
|
2527
|
+
arbitrary: variantArbitrary
|
|
2528
|
+
};
|
|
2529
|
+
let matchKey = variantName;
|
|
2530
|
+
if (variantArbitrary && variantValue) {
|
|
2531
|
+
if (variantName) {
|
|
2532
|
+
matchKey = `${variantName}-[${variantValue}]`;
|
|
2533
|
+
parsedModifier.type = matchKey;
|
|
2534
|
+
} else {
|
|
2535
|
+
matchKey = `[${variantValue}]`;
|
|
2536
|
+
parsedModifier.type = matchKey;
|
|
2537
|
+
}
|
|
2538
|
+
} else if (variantValue) {
|
|
2539
|
+
matchKey = `${variantName}-[${variantValue}]`;
|
|
2540
|
+
parsedModifier.type = matchKey;
|
|
2541
|
+
}
|
|
2542
|
+
const plugin = getModifier(ctx).find((p) => p.match(matchKey, ctx));
|
|
2543
|
+
if (!plugin) {
|
|
2544
|
+
console.warn(`[jsonToAst] Unknown variant: "${matchKey}"`);
|
|
2545
|
+
continue;
|
|
2546
|
+
}
|
|
2547
|
+
if (plugin.modifySelector) {
|
|
2548
|
+
const result = plugin.modifySelector({
|
|
2549
|
+
selector,
|
|
2550
|
+
fullClassName: "JSON_GENERATED",
|
|
2551
|
+
// Placeholder
|
|
2552
|
+
mod: parsedModifier,
|
|
2553
|
+
context: ctx,
|
|
2554
|
+
variantChain: [],
|
|
2555
|
+
// We might need to pass the full chain if needed
|
|
2556
|
+
index: i
|
|
2557
|
+
});
|
|
2558
|
+
const identityWithWrap = plugin.wrap && (result === "&" || typeof result === "object" && !Array.isArray(result) && result.selector === "&" || Array.isArray(result) && result.length === 1 && result[0].selector === "&");
|
|
2559
|
+
if (identityWithWrap) ;
|
|
2560
|
+
else if (typeof result === "string" && result.includes("&")) {
|
|
2561
|
+
wrappers.push({ type: "rule", selector: result });
|
|
2562
|
+
} else if (typeof result === "object" && !Array.isArray(result) && result.selector) {
|
|
2563
|
+
const r = result;
|
|
2564
|
+
const wrappingType = r.wrappingType || "rule";
|
|
2565
|
+
wrappers.push({
|
|
2566
|
+
type: wrappingType,
|
|
2567
|
+
selector: r.selector,
|
|
2568
|
+
flatten: r.flatten,
|
|
2569
|
+
source: r.source
|
|
2570
|
+
});
|
|
2571
|
+
} else if (Array.isArray(result)) {
|
|
2572
|
+
wrappers.push({
|
|
2573
|
+
type: "wrap",
|
|
2574
|
+
items: result.map((r) => ({
|
|
2575
|
+
type: r.wrappingType || "rule",
|
|
2576
|
+
selector: r.selector,
|
|
2577
|
+
source: r.source,
|
|
2578
|
+
nodes: []
|
|
2579
|
+
// Placeholder, will be filled when wrapping
|
|
2580
|
+
}))
|
|
2581
|
+
});
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
if (plugin.wrap) {
|
|
2585
|
+
wrappers.push({ type: "wrap", items: plugin.wrap(parsedModifier, ctx) });
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2588
|
+
for (let i = 0; i < wrappers.length; i++) {
|
|
2589
|
+
const wrap = wrappers[i];
|
|
2590
|
+
if (wrap.type === "wrap") {
|
|
2591
|
+
ast = wrap.items.map((item) => item.type === "rule" || item.type === "style-rule" || item.type === "at-rule" || item.type === "at-root" ? { ...item, nodes: [...item.nodes || [], ...ast] } : item);
|
|
2592
|
+
} else if (wrap.type === "style-rule") {
|
|
2593
|
+
ast = [
|
|
2594
|
+
{
|
|
2595
|
+
type: "style-rule",
|
|
2596
|
+
selector: wrap.selector,
|
|
2597
|
+
source: wrap.source,
|
|
2598
|
+
nodes: Array.isArray(ast) ? ast : [ast]
|
|
2599
|
+
}
|
|
2600
|
+
];
|
|
2601
|
+
} else if (wrap.type === "at-rule") {
|
|
2602
|
+
ast = [
|
|
2603
|
+
{
|
|
2604
|
+
type: "at-rule",
|
|
2605
|
+
name: wrap.name || "media",
|
|
2606
|
+
params: wrap.params,
|
|
2607
|
+
source: wrap.source,
|
|
2608
|
+
nodes: Array.isArray(ast) ? ast : [ast]
|
|
2609
|
+
}
|
|
2610
|
+
];
|
|
2611
|
+
} else if (wrap.type === "rule") {
|
|
2612
|
+
ast = [
|
|
2613
|
+
{
|
|
2614
|
+
type: "rule",
|
|
2615
|
+
selector: wrap.selector,
|
|
2616
|
+
source: wrap.source,
|
|
2617
|
+
nodes: Array.isArray(ast) ? ast : [ast]
|
|
2618
|
+
}
|
|
2619
|
+
];
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
return ast;
|
|
2624
|
+
}
|
|
2625
|
+
function generateCssFromJson(inputs, ctx, opts) {
|
|
2626
|
+
const allAtRootNodes = [];
|
|
2627
|
+
const cssList = [];
|
|
2628
|
+
inputs.forEach((input) => {
|
|
2629
|
+
const ast = jsonToAst(input, ctx);
|
|
2630
|
+
const cleanAst = optimizeAst(ast);
|
|
2631
|
+
cleanAst.forEach((node) => {
|
|
2632
|
+
if (node.type === "at-root") {
|
|
2633
|
+
allAtRootNodes.push(...node.nodes);
|
|
2634
|
+
}
|
|
2635
|
+
});
|
|
2636
|
+
let reconstructedName = input.utility.name;
|
|
2637
|
+
if (input.utility.value) reconstructedName += `-${input.utility.value}`;
|
|
2638
|
+
if (input.utility.arbitrary) reconstructedName = `${input.utility.name}-[${input.utility.value}]`;
|
|
2639
|
+
if (input.variants) {
|
|
2640
|
+
const variantsStr = input.variants.map((v) => typeof v === "string" ? v : v.name).join(":");
|
|
2641
|
+
reconstructedName = `${variantsStr}:${reconstructedName}`;
|
|
2642
|
+
}
|
|
2643
|
+
const hasStyleRule = cleanAst.some((node) => node.type === "style-rule");
|
|
2644
|
+
const css = astToCss(cleanAst, hasStyleRule ? void 0 : `.${reconstructedName.replace(/[^a-zA-Z0-9-_]/g, "\\$&")}`, {
|
|
2645
|
+
minify: opts?.minify,
|
|
2646
|
+
important: input.utility.important ?? false
|
|
2647
|
+
});
|
|
2648
|
+
if (css) cssList.push(css);
|
|
2649
|
+
});
|
|
2650
|
+
const rootCss = rootToCss(allAtRootNodes);
|
|
2651
|
+
const finalCss = `${rootCss ? `:root,:host {${rootCss}}` : ""}${cssList.join(opts?.minify ? "" : "\n")}`;
|
|
2652
|
+
return finalCss;
|
|
2653
|
+
}
|
|
2445
2654
|
function parseFraction(input) {
|
|
2446
2655
|
if (input.includes("/")) {
|
|
2447
2656
|
const [num, denom] = input.split("/").map(Number);
|
|
@@ -3779,7 +3988,7 @@ functionalUtility({
|
|
|
3779
3988
|
["--baro-ring-inset", "inset"],
|
|
3780
3989
|
["--baro-ring-offset-width", "0px"],
|
|
3781
3990
|
["--baro-ring-offset-color", "#fff"],
|
|
3782
|
-
["--baro-inset-ring-color", "
|
|
3991
|
+
["--baro-inset-ring-color", "currentcolor"],
|
|
3783
3992
|
[
|
|
3784
3993
|
"--baro-inset-ring-shadow",
|
|
3785
3994
|
`var(--baro-ring-inset) 0 0 0 calc(${px} + var(--baro-ring-offset-width)) var(--baro-inset-ring-color, currentcolor)`
|
|
@@ -3787,7 +3996,7 @@ functionalUtility({
|
|
|
3787
3996
|
["--baro-ring-offset-shadow", `0 0 #0000`],
|
|
3788
3997
|
[
|
|
3789
3998
|
"box-shadow",
|
|
3790
|
-
"var(--baro-inset-shadow), var(--baro-inset-ring-shadow), var(--baro-ring-offset-shadow), var(--baro-ring-shadow), var(--baro-shadow)"
|
|
3999
|
+
"var(--baro-inset-shadow, 0 0 #0000), var(--baro-inset-ring-shadow), var(--baro-ring-offset-shadow, 0 0 #0000), var(--baro-ring-shadow, 0 0 #0000), var(--baro-shadow, 0 0 #0000)"
|
|
3791
4000
|
]
|
|
3792
4001
|
]);
|
|
3793
4002
|
});
|
|
@@ -4105,6 +4314,18 @@ functionalUtility({
|
|
|
4105
4314
|
description: "mask-size utility (static, arbitrary, custom property supported)",
|
|
4106
4315
|
category: "effects"
|
|
4107
4316
|
});
|
|
4317
|
+
functionalUtility({
|
|
4318
|
+
name: "mask-linear-from",
|
|
4319
|
+
handleBareValue: ({ value }) => /^(?:100|[1-9]?\d)%$/.test(value) ? value : null,
|
|
4320
|
+
handle: (value) => [
|
|
4321
|
+
decl("mask-image", "var(--tw-mask-linear), var(--tw-mask-radial, linear-gradient(#fff, #fff)), var(--tw-mask-conic, linear-gradient(#fff, #fff))"),
|
|
4322
|
+
decl("mask-composite", "intersect"),
|
|
4323
|
+
decl("--tw-mask-linear-stops", "var(--tw-mask-linear-position, 0deg), var(--tw-mask-linear-from-color, black) var(--tw-mask-linear-from-position, 0%), var(--tw-mask-linear-to-color, transparent) var(--tw-mask-linear-to-position, 100%)"),
|
|
4324
|
+
decl("--tw-mask-linear", "linear-gradient(var(--tw-mask-linear-stops))"),
|
|
4325
|
+
decl("--tw-mask-linear-from-position", value)
|
|
4326
|
+
],
|
|
4327
|
+
category: "effects"
|
|
4328
|
+
});
|
|
4108
4329
|
functionalUtility({
|
|
4109
4330
|
name: "mask",
|
|
4110
4331
|
supportsArbitrary: true,
|
|
@@ -6895,7 +7116,11 @@ functionalUtility({
|
|
|
6895
7116
|
});
|
|
6896
7117
|
staticUtility("forced-color-adjust-auto", [["forced-color-adjust", "auto"]], { category: "accessibility" });
|
|
6897
7118
|
staticUtility("forced-color-adjust-none", [["forced-color-adjust", "none"]], { category: "accessibility" });
|
|
6898
|
-
staticModifier("hover", ["&:hover"], {
|
|
7119
|
+
staticModifier("hover", ["&:hover"], {
|
|
7120
|
+
order: 50,
|
|
7121
|
+
source: "pseudo",
|
|
7122
|
+
wrap: () => [atRule("media", "(hover: hover)", [])]
|
|
7123
|
+
});
|
|
6899
7124
|
staticModifier("focus", ["&:focus"], { order: 50, source: "pseudo" });
|
|
6900
7125
|
staticModifier("active", ["&:active"], { order: 50, source: "pseudo" });
|
|
6901
7126
|
staticModifier("visited", ["&:visited"], { order: 50, source: "pseudo" });
|
|
@@ -7735,11 +7960,14 @@ export {
|
|
|
7735
7960
|
functionalModifier,
|
|
7736
7961
|
functionalUtility,
|
|
7737
7962
|
generateCss,
|
|
7963
|
+
generateCssFromJson,
|
|
7738
7964
|
generateCssRules,
|
|
7965
|
+
getAstCacheStats,
|
|
7739
7966
|
getModifier,
|
|
7740
7967
|
getPreflightCSS,
|
|
7741
7968
|
getUtility,
|
|
7742
7969
|
hasPreset,
|
|
7970
|
+
jsonToAst,
|
|
7743
7971
|
mergeAstTreeList,
|
|
7744
7972
|
modifierRegistry,
|
|
7745
7973
|
optimizeAst,
|
|
@@ -7748,10 +7976,12 @@ export {
|
|
|
7748
7976
|
parseResultCache,
|
|
7749
7977
|
property,
|
|
7750
7978
|
raw,
|
|
7979
|
+
registerModifier,
|
|
7751
7980
|
registerUtility,
|
|
7752
7981
|
resolveTheme,
|
|
7753
7982
|
rootToCss,
|
|
7754
7983
|
rule,
|
|
7984
|
+
setContextCacheReset,
|
|
7755
7985
|
staticModifier,
|
|
7756
7986
|
staticUtility,
|
|
7757
7987
|
styleRule,
|