@bamboocss/core 1.11.1 → 1.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-CfYAbeIz.mjs +13 -0
- package/dist/index.cjs +4055 -0
- package/dist/index.d.cts +1025 -0
- package/dist/index.d.mts +1023 -0
- package/dist/index.mjs +3775 -4106
- package/package.json +13 -13
- package/dist/index.js +0 -4327
package/dist/index.js
DELETED
|
@@ -1,4327 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
Breakpoints: () => Breakpoints,
|
|
34
|
-
Conditions: () => Conditions,
|
|
35
|
-
Context: () => Context,
|
|
36
|
-
FileMatcher: () => FileMatcher,
|
|
37
|
-
ImportMap: () => ImportMap,
|
|
38
|
-
JsxEngine: () => JsxEngine,
|
|
39
|
-
Layers: () => Layers,
|
|
40
|
-
Patterns: () => Patterns,
|
|
41
|
-
Recipes: () => Recipes,
|
|
42
|
-
RuleProcessor: () => RuleProcessor,
|
|
43
|
-
StaticCss: () => StaticCss,
|
|
44
|
-
StyleDecoder: () => StyleDecoder,
|
|
45
|
-
StyleEncoder: () => StyleEncoder,
|
|
46
|
-
Stylesheet: () => Stylesheet,
|
|
47
|
-
Utility: () => Utility,
|
|
48
|
-
expandNestedCss: () => expandNestedCss,
|
|
49
|
-
extractParentSelectors: () => extractParentSelectors,
|
|
50
|
-
extractTrailingPseudos: () => extractTrailingPseudos,
|
|
51
|
-
messages: () => messages_exports,
|
|
52
|
-
optimizeCss: () => optimizeCss,
|
|
53
|
-
stringify: () => stringify
|
|
54
|
-
});
|
|
55
|
-
module.exports = __toCommonJS(index_exports);
|
|
56
|
-
|
|
57
|
-
// src/messages.ts
|
|
58
|
-
var messages_exports = {};
|
|
59
|
-
__export(messages_exports, {
|
|
60
|
-
artifactsGenerated: () => artifactsGenerated,
|
|
61
|
-
buildComplete: () => buildComplete,
|
|
62
|
-
codegenComplete: () => codegenComplete,
|
|
63
|
-
configExists: () => configExists,
|
|
64
|
-
configWatch: () => configWatch,
|
|
65
|
-
cssArtifactComplete: () => cssArtifactComplete,
|
|
66
|
-
exclamation: () => exclamation,
|
|
67
|
-
getMessages: () => getMessages,
|
|
68
|
-
noExtract: () => noExtract,
|
|
69
|
-
thankYou: () => thankYou,
|
|
70
|
-
watch: () => watch
|
|
71
|
-
});
|
|
72
|
-
var import_logger = require("@bamboocss/logger");
|
|
73
|
-
var import_outdent = require("outdent");
|
|
74
|
-
var tick = import_logger.colors.green().bold("\u2714\uFE0F");
|
|
75
|
-
var artifactsGenerated = (ctx) => {
|
|
76
|
-
const {
|
|
77
|
-
config: { outdir, themes },
|
|
78
|
-
recipes,
|
|
79
|
-
patterns,
|
|
80
|
-
tokens,
|
|
81
|
-
jsx
|
|
82
|
-
} = ctx;
|
|
83
|
-
return () => [
|
|
84
|
-
import_outdent.outdent`
|
|
85
|
-
${tick} ${(0, import_logger.quote)(outdir, "/css")}: the css function to author styles
|
|
86
|
-
`,
|
|
87
|
-
!tokens.isEmpty && import_outdent.outdent`
|
|
88
|
-
${tick} ${(0, import_logger.quote)(outdir, "/tokens")}: the css variables and js function to query your tokens
|
|
89
|
-
`,
|
|
90
|
-
!patterns.isEmpty() && !ctx.isTemplateLiteralSyntax && import_outdent.outdent`
|
|
91
|
-
${tick} ${(0, import_logger.quote)(outdir, "/patterns")}: functions to implement and apply common layout patterns
|
|
92
|
-
`,
|
|
93
|
-
!recipes.isEmpty() && import_outdent.outdent`
|
|
94
|
-
${tick} ${(0, import_logger.quote)(outdir, "/recipes")}: functions to create multi-variant styles
|
|
95
|
-
`,
|
|
96
|
-
jsx.framework && import_outdent.outdent`
|
|
97
|
-
${tick} ${(0, import_logger.quote)(outdir, "/jsx")}: styled jsx elements for ${jsx.framework}
|
|
98
|
-
`,
|
|
99
|
-
themes && import_outdent.outdent`
|
|
100
|
-
${tick} ${(0, import_logger.quote)(outdir, "/themes")}: theme variants for your design system
|
|
101
|
-
`,
|
|
102
|
-
"\n"
|
|
103
|
-
].filter(Boolean).join("\n");
|
|
104
|
-
};
|
|
105
|
-
var configExists = (cmd) => import_outdent.outdent`
|
|
106
|
-
\n
|
|
107
|
-
It looks like you already have bamboo created\`.
|
|
108
|
-
|
|
109
|
-
You can now run ${(0, import_logger.quote)(cmd, " bamboo --watch")}.
|
|
110
|
-
|
|
111
|
-
`;
|
|
112
|
-
var thankYou = () => import_outdent.outdent`
|
|
113
|
-
|
|
114
|
-
🚀 Thanks for choosing ${import_logger.colors.cyan("Bamboo")})} to write your css.
|
|
115
|
-
|
|
116
|
-
You are set up to start using Bamboo!
|
|
117
|
-
|
|
118
|
-
`;
|
|
119
|
-
var codegenComplete = () => import_outdent.outdent`
|
|
120
|
-
|
|
121
|
-
${import_logger.colors.bold().cyan("Next steps:")}
|
|
122
|
-
|
|
123
|
-
[1] Create a ${(0, import_logger.quote)("index.css")} file in your project that contains:
|
|
124
|
-
|
|
125
|
-
@layer reset, base, tokens, recipes, utilities;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
[2] Import the ${(0, import_logger.quote)("index.css")} file at the root of your project.
|
|
129
|
-
|
|
130
|
-
`;
|
|
131
|
-
var noExtract = () => import_outdent.outdent`
|
|
132
|
-
No style object or props were detected in your source files.
|
|
133
|
-
If this is unexpected, double-check the \`include\` options in your Bamboo config\n
|
|
134
|
-
`;
|
|
135
|
-
var watch = () => import_outdent.outdent`
|
|
136
|
-
Watching for file changes...
|
|
137
|
-
`;
|
|
138
|
-
var configWatch = () => import_outdent.outdent`
|
|
139
|
-
Watching for config file changes...
|
|
140
|
-
`;
|
|
141
|
-
var buildComplete = (count) => import_outdent.outdent`
|
|
142
|
-
Successfully extracted css from ${count} file(s) ✨
|
|
143
|
-
`;
|
|
144
|
-
var randomWords = ["Sweet", "Divine", "Bamboolicious", "Super"];
|
|
145
|
-
var pickRandom = (arr) => arr[Math.floor(Math.random() * arr.length)];
|
|
146
|
-
var exclamation = () => `\u{1F38B} ${pickRandom(randomWords)}! \u2728`;
|
|
147
|
-
var cssArtifactComplete = (type) => `Successfully generated ${type} css artifact \u2728`;
|
|
148
|
-
var getMessages = (ctx) => ({
|
|
149
|
-
artifactsGenerated: artifactsGenerated(ctx),
|
|
150
|
-
configExists,
|
|
151
|
-
thankYou,
|
|
152
|
-
codegenComplete,
|
|
153
|
-
noExtract,
|
|
154
|
-
watch,
|
|
155
|
-
buildComplete,
|
|
156
|
-
configWatch,
|
|
157
|
-
cssArtifactComplete,
|
|
158
|
-
exclamation
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
// src/breakpoints.ts
|
|
162
|
-
var import_shared = require("@bamboocss/shared");
|
|
163
|
-
var Breakpoints = class {
|
|
164
|
-
constructor(breakpoints) {
|
|
165
|
-
this.breakpoints = breakpoints;
|
|
166
|
-
this.sorted = sortBreakpoints(breakpoints);
|
|
167
|
-
this.values = Object.fromEntries(this.sorted);
|
|
168
|
-
this.keys = ["base", ...Object.keys(this.values)];
|
|
169
|
-
this.ranges = this.getRanges();
|
|
170
|
-
this.conditions = this.getConditions();
|
|
171
|
-
}
|
|
172
|
-
sorted;
|
|
173
|
-
values;
|
|
174
|
-
keys;
|
|
175
|
-
ranges;
|
|
176
|
-
conditions;
|
|
177
|
-
get = (name) => {
|
|
178
|
-
return this.values[name];
|
|
179
|
-
};
|
|
180
|
-
build = ({ min, max }) => {
|
|
181
|
-
if (min == null && max == null) return "";
|
|
182
|
-
return ["screen", min && `(min-width: ${min})`, max && `(max-width: ${max})`].filter(Boolean).join(" and ");
|
|
183
|
-
};
|
|
184
|
-
only = (name) => {
|
|
185
|
-
const { min, max } = this.get(name);
|
|
186
|
-
return this.build({ min, max });
|
|
187
|
-
};
|
|
188
|
-
getRanges = () => {
|
|
189
|
-
const breakpoints = Object.keys(this.values);
|
|
190
|
-
const permuations = getPermutations(breakpoints);
|
|
191
|
-
const values = breakpoints.flatMap((name) => {
|
|
192
|
-
const value = this.get(name);
|
|
193
|
-
const down = [`${name}Down`, this.build({ max: adjust(value.min) })];
|
|
194
|
-
const up = [name, this.build({ min: value.min })];
|
|
195
|
-
const only = [`${name}Only`, this.only(name)];
|
|
196
|
-
return [up, only, down];
|
|
197
|
-
}).filter(([_, value]) => value !== "").concat(
|
|
198
|
-
permuations.map(([min, max]) => {
|
|
199
|
-
const minValue = this.get(min);
|
|
200
|
-
const maxValue2 = this.get(max);
|
|
201
|
-
return [`${min}To${(0, import_shared.capitalize)(max)}`, this.build({ min: minValue.min, max: adjust(maxValue2.min) })];
|
|
202
|
-
})
|
|
203
|
-
);
|
|
204
|
-
return Object.fromEntries(values);
|
|
205
|
-
};
|
|
206
|
-
getConditions = () => {
|
|
207
|
-
const values = Object.entries(this.ranges).map(([key, value]) => {
|
|
208
|
-
return [key, toCondition(key, value)];
|
|
209
|
-
});
|
|
210
|
-
return Object.fromEntries(values);
|
|
211
|
-
};
|
|
212
|
-
getCondition = (key) => {
|
|
213
|
-
return this.conditions[key];
|
|
214
|
-
};
|
|
215
|
-
expandScreenAtRule = (root) => {
|
|
216
|
-
root.walkAtRules("breakpoint", (rule) => {
|
|
217
|
-
const value = this.getCondition(rule.params);
|
|
218
|
-
if (!value) {
|
|
219
|
-
throw rule.error(`No \`${rule.params}\` screen found.`);
|
|
220
|
-
}
|
|
221
|
-
if (value.type !== "at-rule") {
|
|
222
|
-
throw rule.error(`\`${rule.params}\` is not a valid screen.`);
|
|
223
|
-
}
|
|
224
|
-
rule.name = "media";
|
|
225
|
-
rule.params = value.params;
|
|
226
|
-
});
|
|
227
|
-
};
|
|
228
|
-
};
|
|
229
|
-
function adjust(value) {
|
|
230
|
-
const computedMax = parseFloat((0, import_shared.toPx)(value) ?? "") - 0.04;
|
|
231
|
-
return (0, import_shared.toRem)(`${computedMax}px`);
|
|
232
|
-
}
|
|
233
|
-
function sortBreakpoints(breakpoints) {
|
|
234
|
-
return Object.entries(breakpoints).sort(([, minA], [, minB]) => {
|
|
235
|
-
return parseInt(minA, 10) < parseInt(minB, 10) ? -1 : 1;
|
|
236
|
-
}).map(([name, min], index, entries) => {
|
|
237
|
-
let max = null;
|
|
238
|
-
if (index <= entries.length - 1) {
|
|
239
|
-
max = entries[index + 1]?.[1];
|
|
240
|
-
}
|
|
241
|
-
if (max != null) {
|
|
242
|
-
max = adjust(max);
|
|
243
|
-
}
|
|
244
|
-
return [name, { name, min: (0, import_shared.toRem)(min), max }];
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
var toCondition = (key, value) => ({
|
|
248
|
-
type: "at-rule",
|
|
249
|
-
name: "breakpoint",
|
|
250
|
-
value: key,
|
|
251
|
-
raw: `@media ${value}`,
|
|
252
|
-
params: value
|
|
253
|
-
});
|
|
254
|
-
function getPermutations(values) {
|
|
255
|
-
const result = [];
|
|
256
|
-
values.forEach((current, index) => {
|
|
257
|
-
let idx = index;
|
|
258
|
-
idx++;
|
|
259
|
-
let next = values[idx];
|
|
260
|
-
while (next) {
|
|
261
|
-
result.push([current, next]);
|
|
262
|
-
idx++;
|
|
263
|
-
next = values[idx];
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
return result;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// src/conditions.ts
|
|
270
|
-
var import_logger2 = require("@bamboocss/logger");
|
|
271
|
-
var import_shared3 = require("@bamboocss/shared");
|
|
272
|
-
|
|
273
|
-
// src/parse-condition.ts
|
|
274
|
-
var import_postcss2 = require("postcss");
|
|
275
|
-
|
|
276
|
-
// src/safe-parse.ts
|
|
277
|
-
var import_postcss = __toESM(require("postcss"));
|
|
278
|
-
function safeParse(str) {
|
|
279
|
-
try {
|
|
280
|
-
return import_postcss.default.parse(str);
|
|
281
|
-
} catch {
|
|
282
|
-
return import_postcss.default.root();
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// src/parse-condition.ts
|
|
287
|
-
function parseAtRule(value) {
|
|
288
|
-
const result = safeParse(value);
|
|
289
|
-
const rule = result.nodes[0];
|
|
290
|
-
return {
|
|
291
|
-
type: "at-rule",
|
|
292
|
-
name: rule.name,
|
|
293
|
-
value: rule.params,
|
|
294
|
-
raw: value,
|
|
295
|
-
params: rule.params
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
function parseObjectCondition(obj) {
|
|
299
|
-
const blocks = [];
|
|
300
|
-
function traverse2(node, path) {
|
|
301
|
-
for (const [key, value] of Object.entries(node)) {
|
|
302
|
-
if (value === "@slot") {
|
|
303
|
-
const parts = [...path, key];
|
|
304
|
-
const parsed = parseCondition(parts);
|
|
305
|
-
if (parsed && parsed.type === "mixed" && parsed.value.length > 0) {
|
|
306
|
-
blocks.push(parsed);
|
|
307
|
-
}
|
|
308
|
-
} else if (typeof value === "object" && value !== null) {
|
|
309
|
-
traverse2(value, [...path, key]);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
traverse2(obj, []);
|
|
314
|
-
if (blocks.length === 0) return void 0;
|
|
315
|
-
if (blocks.length === 1) return blocks[0];
|
|
316
|
-
return {
|
|
317
|
-
type: "multi-block",
|
|
318
|
-
value: blocks,
|
|
319
|
-
raw: obj
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
function parseCondition(condition) {
|
|
323
|
-
if (Array.isArray(condition)) {
|
|
324
|
-
const value = condition.map(parseCondition).filter(Boolean);
|
|
325
|
-
return {
|
|
326
|
-
type: "mixed",
|
|
327
|
-
raw: condition,
|
|
328
|
-
value
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
if (typeof condition === "object" && condition !== null) {
|
|
332
|
-
return parseObjectCondition(condition);
|
|
333
|
-
}
|
|
334
|
-
if (condition.startsWith("@")) {
|
|
335
|
-
return parseAtRule(condition);
|
|
336
|
-
}
|
|
337
|
-
let type;
|
|
338
|
-
if (condition.startsWith("&")) {
|
|
339
|
-
type = "self-nesting";
|
|
340
|
-
} else if (condition.endsWith(" &")) {
|
|
341
|
-
type = "parent-nesting";
|
|
342
|
-
} else if (condition.includes("&")) {
|
|
343
|
-
type = "combinator-nesting";
|
|
344
|
-
}
|
|
345
|
-
if (type) {
|
|
346
|
-
return { type, value: condition, raw: condition };
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
// src/sort-at-rules.ts
|
|
351
|
-
var minMaxWidth = /(!?\(\s*min(-device-)?-width)(.|\n)+\(\s*max(-device)?-width/i;
|
|
352
|
-
var minWidth = /\(\s*min(-device)?-width/i;
|
|
353
|
-
var maxMinWidth = /(!?\(\s*max(-device)?-width)(.|\n)+\(\s*min(-device)?-width/i;
|
|
354
|
-
var maxWidth = /\(\s*max(-device)?-width/i;
|
|
355
|
-
var isMinWidth = _testQuery(minMaxWidth, maxMinWidth, minWidth);
|
|
356
|
-
var isMaxWidth = _testQuery(maxMinWidth, minMaxWidth, maxWidth);
|
|
357
|
-
var minMaxHeight = /(!?\(\s*min(-device)?-height)(.|\n)+\(\s*max(-device)?-height/i;
|
|
358
|
-
var minHeight = /\(\s*min(-device)?-height/i;
|
|
359
|
-
var maxMinHeight = /(!?\(\s*max(-device)?-height)(.|\n)+\(\s*min(-device)?-height/i;
|
|
360
|
-
var maxHeight = /\(\s*max(-device)?-height/i;
|
|
361
|
-
var isMinHeight = _testQuery(minMaxHeight, maxMinHeight, minHeight);
|
|
362
|
-
var isMaxHeight = _testQuery(maxMinHeight, minMaxHeight, maxHeight);
|
|
363
|
-
var isPrint = /print/i;
|
|
364
|
-
var isPrintOnly = /^print$/i;
|
|
365
|
-
var maxValue = Number.MAX_VALUE;
|
|
366
|
-
function getQueryLength(query) {
|
|
367
|
-
let length = /(-?\d*\.?\d+)(ch|em|ex|px|rem)/.exec(query);
|
|
368
|
-
if (length === null && (isMinWidth(query) || isMinHeight(query))) {
|
|
369
|
-
length = /(\d)/.exec(query);
|
|
370
|
-
}
|
|
371
|
-
if (length === "0") {
|
|
372
|
-
return 0;
|
|
373
|
-
}
|
|
374
|
-
if (length === null) {
|
|
375
|
-
return maxValue;
|
|
376
|
-
}
|
|
377
|
-
let number = length[1];
|
|
378
|
-
const unit = length[2];
|
|
379
|
-
switch (unit) {
|
|
380
|
-
case "ch":
|
|
381
|
-
number = parseFloat(number) * 8.8984375;
|
|
382
|
-
break;
|
|
383
|
-
case "em":
|
|
384
|
-
case "rem":
|
|
385
|
-
number = parseFloat(number) * 16;
|
|
386
|
-
break;
|
|
387
|
-
case "ex":
|
|
388
|
-
number = parseFloat(number) * 8.296875;
|
|
389
|
-
break;
|
|
390
|
-
case "px":
|
|
391
|
-
number = parseFloat(number);
|
|
392
|
-
break;
|
|
393
|
-
}
|
|
394
|
-
return +number;
|
|
395
|
-
}
|
|
396
|
-
function _testQuery(doubleTestTrue, doubleTestFalse, singleTest) {
|
|
397
|
-
return function(query) {
|
|
398
|
-
if (doubleTestTrue.test(query)) {
|
|
399
|
-
return true;
|
|
400
|
-
} else if (doubleTestFalse.test(query)) {
|
|
401
|
-
return false;
|
|
402
|
-
}
|
|
403
|
-
return singleTest.test(query);
|
|
404
|
-
};
|
|
405
|
-
}
|
|
406
|
-
function _testIsPrint(a, b) {
|
|
407
|
-
const isPrintA = isPrint.test(a);
|
|
408
|
-
const isPrintOnlyA = isPrintOnly.test(a);
|
|
409
|
-
const isPrintB = isPrint.test(b);
|
|
410
|
-
const isPrintOnlyB = isPrintOnly.test(b);
|
|
411
|
-
if (isPrintA && isPrintB) {
|
|
412
|
-
if (!isPrintOnlyA && isPrintOnlyB) {
|
|
413
|
-
return 1;
|
|
414
|
-
}
|
|
415
|
-
if (isPrintOnlyA && !isPrintOnlyB) {
|
|
416
|
-
return -1;
|
|
417
|
-
}
|
|
418
|
-
return a.localeCompare(b);
|
|
419
|
-
}
|
|
420
|
-
if (isPrintA) {
|
|
421
|
-
return 1;
|
|
422
|
-
}
|
|
423
|
-
if (isPrintB) {
|
|
424
|
-
return -1;
|
|
425
|
-
}
|
|
426
|
-
return null;
|
|
427
|
-
}
|
|
428
|
-
function createSort(config = {}) {
|
|
429
|
-
const { unitlessMqAlwaysFirst } = config;
|
|
430
|
-
return function sortCSSmq(a, b) {
|
|
431
|
-
const testIsPrint = _testIsPrint(a, b);
|
|
432
|
-
if (testIsPrint !== null) {
|
|
433
|
-
return testIsPrint;
|
|
434
|
-
}
|
|
435
|
-
const minA = isMinWidth(a) || isMinHeight(a);
|
|
436
|
-
const maxA = isMaxWidth(a) || isMaxHeight(a);
|
|
437
|
-
const minB = isMinWidth(b) || isMinHeight(b);
|
|
438
|
-
const maxB = isMaxWidth(b) || isMaxHeight(b);
|
|
439
|
-
if (unitlessMqAlwaysFirst && (!minA && !maxA || !minB && !maxB)) {
|
|
440
|
-
if (!minA && !maxA && !minB && !maxB) {
|
|
441
|
-
return a.localeCompare(b);
|
|
442
|
-
}
|
|
443
|
-
return !minB && !maxB ? 1 : -1;
|
|
444
|
-
} else {
|
|
445
|
-
if (minA && maxB) {
|
|
446
|
-
return -1;
|
|
447
|
-
}
|
|
448
|
-
if (maxA && minB) {
|
|
449
|
-
return 1;
|
|
450
|
-
}
|
|
451
|
-
const lengthA = getQueryLength(a);
|
|
452
|
-
const lengthB = getQueryLength(b);
|
|
453
|
-
if (lengthA === maxValue && lengthB === maxValue) {
|
|
454
|
-
return a.localeCompare(b);
|
|
455
|
-
} else if (lengthA === maxValue) {
|
|
456
|
-
return 1;
|
|
457
|
-
} else if (lengthB === maxValue) {
|
|
458
|
-
return -1;
|
|
459
|
-
}
|
|
460
|
-
if (lengthA > lengthB) {
|
|
461
|
-
if (maxA) {
|
|
462
|
-
return -1;
|
|
463
|
-
}
|
|
464
|
-
return 1;
|
|
465
|
-
}
|
|
466
|
-
if (lengthA < lengthB) {
|
|
467
|
-
if (maxA) {
|
|
468
|
-
return 1;
|
|
469
|
-
}
|
|
470
|
-
return -1;
|
|
471
|
-
}
|
|
472
|
-
return a.localeCompare(b);
|
|
473
|
-
}
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
var sortAtRules = createSort();
|
|
477
|
-
|
|
478
|
-
// src/sort-style-rules.ts
|
|
479
|
-
var import_shared2 = require("@bamboocss/shared");
|
|
480
|
-
var hasAtRule = (conditions) => conditions.some((details) => details.type === "at-rule" || details.type === "mixed" || details.type === "multi-block");
|
|
481
|
-
var styleOrder = [":link", ":visited", ":focus-within", ":focus", ":focus-visible", ":hover", ":active"];
|
|
482
|
-
var pseudoSelectorScore = (selector) => {
|
|
483
|
-
const index = styleOrder.findIndex((pseudoClass) => selector.includes(pseudoClass));
|
|
484
|
-
return index + 1;
|
|
485
|
-
};
|
|
486
|
-
var compareSelectors = (a, b) => {
|
|
487
|
-
const aConds = a.conditions;
|
|
488
|
-
const bConds = b.conditions;
|
|
489
|
-
if (aConds.length === bConds.length) {
|
|
490
|
-
const selector1 = aConds[0].value;
|
|
491
|
-
const selector2 = bConds[0].value;
|
|
492
|
-
return pseudoSelectorScore(selector1) - pseudoSelectorScore(selector2);
|
|
493
|
-
}
|
|
494
|
-
return aConds.length - bConds.length;
|
|
495
|
-
};
|
|
496
|
-
var flatten = (conds) => conds.flatMap((cond) => {
|
|
497
|
-
if (cond.type === "mixed") return cond.value;
|
|
498
|
-
if (cond.type === "multi-block") return cond.value.flatMap((block) => block.value);
|
|
499
|
-
return cond;
|
|
500
|
-
});
|
|
501
|
-
var compareAtRuleOrMixed = (a, b) => {
|
|
502
|
-
const aConds = flatten(a.conditions);
|
|
503
|
-
const bConds = flatten(b.conditions);
|
|
504
|
-
let aCond, bCond;
|
|
505
|
-
const max = Math.max(aConds.length, bConds.length);
|
|
506
|
-
for (let i = 0; i < max; i++) {
|
|
507
|
-
aCond = aConds[i];
|
|
508
|
-
bCond = bConds[i];
|
|
509
|
-
if (!aCond) return -1;
|
|
510
|
-
if (!bCond) return 1;
|
|
511
|
-
if (aCond.type === "at-rule" && bCond.type.includes("nesting")) {
|
|
512
|
-
return 1;
|
|
513
|
-
}
|
|
514
|
-
if (aCond.type.includes("nesting") && bCond.type === "at-rule") {
|
|
515
|
-
return -1;
|
|
516
|
-
}
|
|
517
|
-
if (aCond.type === "at-rule" && bCond.type === "at-rule") {
|
|
518
|
-
const atRule1 = aCond.params ?? aCond.raw;
|
|
519
|
-
const atRule2 = bCond.params ?? bCond.raw;
|
|
520
|
-
if (!atRule1) return -1;
|
|
521
|
-
if (!atRule2) return 1;
|
|
522
|
-
const score = sortAtRules(atRule1, atRule2);
|
|
523
|
-
if (score !== 0) {
|
|
524
|
-
return score;
|
|
525
|
-
}
|
|
526
|
-
continue;
|
|
527
|
-
}
|
|
528
|
-
if (aCond.type.includes("nesting") && bCond.type.includes("nesting")) {
|
|
529
|
-
const nextACond = aConds[i + 1];
|
|
530
|
-
const nextBCond = bConds[i + 1];
|
|
531
|
-
if (Boolean(nextACond) === Boolean(nextBCond)) {
|
|
532
|
-
const score = pseudoSelectorScore(aCond.value) - pseudoSelectorScore(bCond.value);
|
|
533
|
-
if (score !== 0) {
|
|
534
|
-
return score;
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
return 0;
|
|
540
|
-
};
|
|
541
|
-
var sortByPropertyPriority = (a, b) => {
|
|
542
|
-
if (a.entry.prop === b.entry.prop) return 0;
|
|
543
|
-
return (0, import_shared2.getPropertyPriority)(a.entry.prop) - (0, import_shared2.getPropertyPriority)(b.entry.prop);
|
|
544
|
-
};
|
|
545
|
-
var sortStyleRules = (styleRules) => {
|
|
546
|
-
const declarations = [];
|
|
547
|
-
const withSelectorsOnly = [];
|
|
548
|
-
const withAtRules = [];
|
|
549
|
-
for (const styleRule of styleRules) {
|
|
550
|
-
if (!styleRule.conditions?.length) {
|
|
551
|
-
declarations.push(styleRule);
|
|
552
|
-
} else if (!hasAtRule(styleRule.conditions)) {
|
|
553
|
-
withSelectorsOnly.push(styleRule);
|
|
554
|
-
} else {
|
|
555
|
-
withAtRules.push(styleRule);
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
withSelectorsOnly.sort((a, b) => {
|
|
559
|
-
const selectorDiff = compareSelectors(a, b);
|
|
560
|
-
if (selectorDiff !== 0) return selectorDiff;
|
|
561
|
-
return sortByPropertyPriority(a, b);
|
|
562
|
-
});
|
|
563
|
-
withAtRules.sort((a, b) => {
|
|
564
|
-
const conditionDiff = compareAtRuleOrMixed(a, b);
|
|
565
|
-
if (conditionDiff !== 0) return conditionDiff;
|
|
566
|
-
return sortByPropertyPriority(a, b);
|
|
567
|
-
});
|
|
568
|
-
const sorted = declarations.sort(sortByPropertyPriority);
|
|
569
|
-
sorted.push(...withSelectorsOnly, ...withAtRules);
|
|
570
|
-
return sorted;
|
|
571
|
-
};
|
|
572
|
-
|
|
573
|
-
// src/conditions.ts
|
|
574
|
-
var isAtRule = (cond) => cond.type === "at-rule";
|
|
575
|
-
var pseudoElementRegex = /::[\w-]/;
|
|
576
|
-
var isPseudoElement = (cond) => typeof cond.raw === "string" && pseudoElementRegex.test(cond.raw);
|
|
577
|
-
var flattenCondition = (cond, originalIndex) => {
|
|
578
|
-
if (cond.type === "mixed") {
|
|
579
|
-
const parts = cond.value;
|
|
580
|
-
return parts.map((part) => ({ cond: part, originalIndex }));
|
|
581
|
-
}
|
|
582
|
-
return [{ cond, originalIndex }];
|
|
583
|
-
};
|
|
584
|
-
var underscoreRegex = /^_/;
|
|
585
|
-
var selectorRegex = /&|@/;
|
|
586
|
-
var Conditions = class {
|
|
587
|
-
constructor(options) {
|
|
588
|
-
this.options = options;
|
|
589
|
-
const { breakpoints: breakpointValues = {}, conditions = {} } = options;
|
|
590
|
-
const breakpoints = new Breakpoints(breakpointValues);
|
|
591
|
-
this.breakpoints = breakpoints;
|
|
592
|
-
const entries = Object.entries(conditions).map(([key, value]) => [`_${key}`, parseCondition(value)]);
|
|
593
|
-
const containers = this.setupContainers();
|
|
594
|
-
const themes = this.setupThemes();
|
|
595
|
-
this.values = {
|
|
596
|
-
...Object.fromEntries(entries),
|
|
597
|
-
...breakpoints.conditions,
|
|
598
|
-
...containers,
|
|
599
|
-
...themes
|
|
600
|
-
};
|
|
601
|
-
}
|
|
602
|
-
values;
|
|
603
|
-
breakpoints;
|
|
604
|
-
setupContainers = () => {
|
|
605
|
-
const { containerNames = [], containerSizes = {} } = this.options;
|
|
606
|
-
const containers = {};
|
|
607
|
-
containerNames.unshift("");
|
|
608
|
-
containerNames.forEach((name) => {
|
|
609
|
-
Object.entries(containerSizes).forEach(([size, value]) => {
|
|
610
|
-
const _value = (0, import_shared3.toRem)(value) ?? value;
|
|
611
|
-
containers[`@${name}/${size}`] = {
|
|
612
|
-
type: "at-rule",
|
|
613
|
-
name: "container",
|
|
614
|
-
value: _value,
|
|
615
|
-
raw: `@container ${name} (min-width: ${_value})`,
|
|
616
|
-
params: `${name} ${value}`
|
|
617
|
-
};
|
|
618
|
-
});
|
|
619
|
-
});
|
|
620
|
-
return containers;
|
|
621
|
-
};
|
|
622
|
-
setupThemes = () => {
|
|
623
|
-
const { themes = {} } = this.options;
|
|
624
|
-
const themeVariants = {};
|
|
625
|
-
Object.entries(themes).forEach(([theme, _themeVariant]) => {
|
|
626
|
-
const condName = this.getThemeName(theme);
|
|
627
|
-
const cond = parseCondition(this.getThemeSelector(theme) + " &");
|
|
628
|
-
if (!cond) return;
|
|
629
|
-
themeVariants[condName] = cond;
|
|
630
|
-
});
|
|
631
|
-
return themeVariants;
|
|
632
|
-
};
|
|
633
|
-
getThemeSelector = (name) => {
|
|
634
|
-
return `[data-bamboo-theme=${name}]`;
|
|
635
|
-
};
|
|
636
|
-
getThemeName = (theme) => {
|
|
637
|
-
return "_theme" + (0, import_shared3.capitalize)(theme);
|
|
638
|
-
};
|
|
639
|
-
finalize = (paths) => {
|
|
640
|
-
return paths.map((path) => {
|
|
641
|
-
if (this.has(path)) {
|
|
642
|
-
return path.replace(underscoreRegex, "");
|
|
643
|
-
}
|
|
644
|
-
if (selectorRegex.test(path)) {
|
|
645
|
-
return `[${(0, import_shared3.withoutSpace)(path.trim())}]`;
|
|
646
|
-
}
|
|
647
|
-
return path;
|
|
648
|
-
});
|
|
649
|
-
};
|
|
650
|
-
shift = (paths) => {
|
|
651
|
-
return paths.map((path) => path.trim()).sort((a, b) => {
|
|
652
|
-
const aIsCondition = this.isCondition(a);
|
|
653
|
-
const bIsCondition = this.isCondition(b);
|
|
654
|
-
if (aIsCondition && !bIsCondition) return 1;
|
|
655
|
-
if (!aIsCondition && bIsCondition) return -1;
|
|
656
|
-
if (!aIsCondition && !bIsCondition) return -1;
|
|
657
|
-
return 0;
|
|
658
|
-
});
|
|
659
|
-
};
|
|
660
|
-
segment = (paths) => {
|
|
661
|
-
const condition = [];
|
|
662
|
-
const selector = [];
|
|
663
|
-
for (const path of paths) {
|
|
664
|
-
if (this.isCondition(path)) {
|
|
665
|
-
condition.push(path);
|
|
666
|
-
} else {
|
|
667
|
-
selector.push(path);
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
return { condition, selector };
|
|
671
|
-
};
|
|
672
|
-
has = (key) => {
|
|
673
|
-
return Object.prototype.hasOwnProperty.call(this.values, key);
|
|
674
|
-
};
|
|
675
|
-
isCondition = (key) => {
|
|
676
|
-
return this.has(key) || !!this.getRaw(key) || (0, import_shared3.isBaseCondition)(key);
|
|
677
|
-
};
|
|
678
|
-
isEmpty = () => {
|
|
679
|
-
return Object.keys(this.values).length === 0;
|
|
680
|
-
};
|
|
681
|
-
get = (key) => {
|
|
682
|
-
const details = this.values[key];
|
|
683
|
-
return details?.raw;
|
|
684
|
-
};
|
|
685
|
-
getRaw = (condNameOrQuery) => {
|
|
686
|
-
if (typeof condNameOrQuery === "string" && this.values[condNameOrQuery]) return this.values[condNameOrQuery];
|
|
687
|
-
try {
|
|
688
|
-
return parseCondition(condNameOrQuery);
|
|
689
|
-
} catch (error) {
|
|
690
|
-
const query = typeof condNameOrQuery === "string" ? condNameOrQuery : JSON.stringify(condNameOrQuery);
|
|
691
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
692
|
-
import_logger2.logger.warn("core:condition", `Failed to parse condition "${query}": ${message}`);
|
|
693
|
-
}
|
|
694
|
-
};
|
|
695
|
-
sort = (conditions) => {
|
|
696
|
-
const rawConditions = conditions.map(this.getRaw).filter(Boolean);
|
|
697
|
-
const flattened = rawConditions.flatMap((cond, index) => flattenCondition(cond, index));
|
|
698
|
-
flattened.sort((a, b) => {
|
|
699
|
-
const aIsAtRule = isAtRule(a.cond);
|
|
700
|
-
const bIsAtRule = isAtRule(b.cond);
|
|
701
|
-
if (aIsAtRule && !bIsAtRule) return -1;
|
|
702
|
-
if (!aIsAtRule && bIsAtRule) return 1;
|
|
703
|
-
const aIsPseudo = isPseudoElement(a.cond);
|
|
704
|
-
const bIsPseudo = isPseudoElement(b.cond);
|
|
705
|
-
if (aIsPseudo !== bIsPseudo) return aIsPseudo ? 1 : -1;
|
|
706
|
-
return a.originalIndex - b.originalIndex;
|
|
707
|
-
});
|
|
708
|
-
return flattened.map((item) => item.cond);
|
|
709
|
-
};
|
|
710
|
-
normalize = (condition) => {
|
|
711
|
-
return (0, import_shared3.isObject)(condition) ? condition : this.getRaw(condition);
|
|
712
|
-
};
|
|
713
|
-
keys = () => {
|
|
714
|
-
return Object.keys(this.values);
|
|
715
|
-
};
|
|
716
|
-
saveOne = (key, value) => {
|
|
717
|
-
const parsed = parseCondition(value);
|
|
718
|
-
if (!parsed) return;
|
|
719
|
-
this.values[`_${key}`] = parsed;
|
|
720
|
-
};
|
|
721
|
-
remove(key) {
|
|
722
|
-
delete this.values[`_${key}`];
|
|
723
|
-
}
|
|
724
|
-
getSortedKeys = () => {
|
|
725
|
-
return Object.keys(this.values).sort((a, b) => {
|
|
726
|
-
const aCondition = this.values[a];
|
|
727
|
-
const bCondition = this.values[b];
|
|
728
|
-
const score = compareAtRuleOrMixed(
|
|
729
|
-
{ entry: {}, conditions: [aCondition] },
|
|
730
|
-
{ entry: {}, conditions: [bCondition] }
|
|
731
|
-
);
|
|
732
|
-
return score;
|
|
733
|
-
});
|
|
734
|
-
};
|
|
735
|
-
};
|
|
736
|
-
|
|
737
|
-
// src/context.ts
|
|
738
|
-
var import_is_valid_prop = require("@bamboocss/is-valid-prop");
|
|
739
|
-
var import_logger5 = require("@bamboocss/logger");
|
|
740
|
-
var import_shared19 = require("@bamboocss/shared");
|
|
741
|
-
var import_token_dictionary = require("@bamboocss/token-dictionary");
|
|
742
|
-
|
|
743
|
-
// src/file.ts
|
|
744
|
-
var import_shared4 = require("@bamboocss/shared");
|
|
745
|
-
var FileEngine = class {
|
|
746
|
-
constructor(context) {
|
|
747
|
-
this.context = context;
|
|
748
|
-
}
|
|
749
|
-
get forceConsistentTypeExtension() {
|
|
750
|
-
return this.context.config.forceConsistentTypeExtension || false;
|
|
751
|
-
}
|
|
752
|
-
get outExtension() {
|
|
753
|
-
return this.context.config.outExtension;
|
|
754
|
-
}
|
|
755
|
-
ext(file) {
|
|
756
|
-
return `${file}.${this.outExtension}`;
|
|
757
|
-
}
|
|
758
|
-
extDts(file) {
|
|
759
|
-
const dts = this.outExtension === "mjs" && this.forceConsistentTypeExtension ? "d.mts" : "d.ts";
|
|
760
|
-
return `${file}.${dts}`;
|
|
761
|
-
}
|
|
762
|
-
__extDts(file) {
|
|
763
|
-
return this.forceConsistentTypeExtension ? this.extDts(file) : file;
|
|
764
|
-
}
|
|
765
|
-
import(mod, file) {
|
|
766
|
-
return `import { ${mod} } from '${this.ext(file)}';`;
|
|
767
|
-
}
|
|
768
|
-
importType(mod, file) {
|
|
769
|
-
return `import type { ${mod} } from '${this.__extDts(file)}';`;
|
|
770
|
-
}
|
|
771
|
-
exportType(mod, file) {
|
|
772
|
-
return `export type { ${mod} } from '${this.__extDts(file)}';`;
|
|
773
|
-
}
|
|
774
|
-
exportStar(file) {
|
|
775
|
-
return `export * from '${this.ext(file)}';`;
|
|
776
|
-
}
|
|
777
|
-
exportTypeStar(file) {
|
|
778
|
-
return `export * from '${this.__extDts(file)}';`;
|
|
779
|
-
}
|
|
780
|
-
isTypeFile(file) {
|
|
781
|
-
return file.endsWith(".d.ts") || file.endsWith(".d.mts");
|
|
782
|
-
}
|
|
783
|
-
jsDocComment(comment, options) {
|
|
784
|
-
const { deprecated, default: defaultValue } = options ?? {};
|
|
785
|
-
if (!comment && !deprecated && !defaultValue) return "";
|
|
786
|
-
const comments = ["/**"];
|
|
787
|
-
if (comment) {
|
|
788
|
-
comments.push(` * ${comment}`, "\n");
|
|
789
|
-
}
|
|
790
|
-
if (deprecated) {
|
|
791
|
-
const suffix = (0, import_shared4.isString)(deprecated) ? ` ${deprecated}` : "";
|
|
792
|
-
comments.push(` * @deprecated${suffix}`);
|
|
793
|
-
}
|
|
794
|
-
if (defaultValue) {
|
|
795
|
-
comments.push(` * @default ${defaultValue}`);
|
|
796
|
-
}
|
|
797
|
-
comments.push(" */");
|
|
798
|
-
return comments.filter((c) => c.trim().length).join("\n");
|
|
799
|
-
}
|
|
800
|
-
/**
|
|
801
|
-
* convert import type { CompositionStyleObject } from './system-types'
|
|
802
|
-
* to import type { CompositionStyleObject } from './system-types.d.ts'
|
|
803
|
-
*/
|
|
804
|
-
rewriteTypeImport(code) {
|
|
805
|
-
return code.replace(/import\s+type\s+\{([^}]+)\}\s+from\s+['"]([^'"]+)['"]/g, this.importType("$1", "$2"));
|
|
806
|
-
}
|
|
807
|
-
};
|
|
808
|
-
|
|
809
|
-
// src/stringify.ts
|
|
810
|
-
var import_shared6 = require("@bamboocss/shared");
|
|
811
|
-
|
|
812
|
-
// src/unitless.ts
|
|
813
|
-
var import_shared5 = require("@bamboocss/shared");
|
|
814
|
-
var keys = {
|
|
815
|
-
animationIterationCount: true,
|
|
816
|
-
aspectRatio: true,
|
|
817
|
-
borderImageOutset: true,
|
|
818
|
-
borderImageSlice: true,
|
|
819
|
-
borderImageWidth: true,
|
|
820
|
-
boxFlex: true,
|
|
821
|
-
boxFlexGroup: true,
|
|
822
|
-
boxOrdinalGroup: true,
|
|
823
|
-
columnCount: true,
|
|
824
|
-
columns: true,
|
|
825
|
-
flex: true,
|
|
826
|
-
flexGrow: true,
|
|
827
|
-
flexPositive: true,
|
|
828
|
-
flexShrink: true,
|
|
829
|
-
flexNegative: true,
|
|
830
|
-
flexOrder: true,
|
|
831
|
-
gridRow: true,
|
|
832
|
-
gridRowEnd: true,
|
|
833
|
-
gridRowSpan: true,
|
|
834
|
-
gridRowStart: true,
|
|
835
|
-
gridColumn: true,
|
|
836
|
-
gridColumnEnd: true,
|
|
837
|
-
gridColumnSpan: true,
|
|
838
|
-
gridColumnStart: true,
|
|
839
|
-
msGridRow: true,
|
|
840
|
-
msGridRowSpan: true,
|
|
841
|
-
msGridColumn: true,
|
|
842
|
-
msGridColumnSpan: true,
|
|
843
|
-
fontWeight: true,
|
|
844
|
-
lineClamp: true,
|
|
845
|
-
lineHeight: true,
|
|
846
|
-
opacity: true,
|
|
847
|
-
order: true,
|
|
848
|
-
orphans: true,
|
|
849
|
-
scale: true,
|
|
850
|
-
tabSize: true,
|
|
851
|
-
widows: true,
|
|
852
|
-
zIndex: true,
|
|
853
|
-
zoom: true,
|
|
854
|
-
WebkitLineClamp: true,
|
|
855
|
-
// SVG-related properties
|
|
856
|
-
fillOpacity: true,
|
|
857
|
-
floodOpacity: true,
|
|
858
|
-
stopOpacity: true,
|
|
859
|
-
strokeDasharray: true,
|
|
860
|
-
strokeDashoffset: true,
|
|
861
|
-
strokeMiterlimit: true,
|
|
862
|
-
strokeOpacity: true,
|
|
863
|
-
strokeWidth: true
|
|
864
|
-
};
|
|
865
|
-
var unitlessProperties = /* @__PURE__ */ new Set();
|
|
866
|
-
Object.keys(keys).forEach((key) => {
|
|
867
|
-
unitlessProperties.add(key);
|
|
868
|
-
unitlessProperties.add((0, import_shared5.hypenateProperty)(key));
|
|
869
|
-
});
|
|
870
|
-
|
|
871
|
-
// src/stringify.ts
|
|
872
|
-
var toString = Object.prototype.toString;
|
|
873
|
-
function stringify(value) {
|
|
874
|
-
const used = /* @__PURE__ */ new WeakSet();
|
|
875
|
-
const write = (cssText, selectors, conditions, name, data, isAtRuleLike, isVariableLike) => {
|
|
876
|
-
if (data === false) return "";
|
|
877
|
-
for (let i = 0; i < conditions.length; ++i) {
|
|
878
|
-
if (!used.has(conditions[i])) {
|
|
879
|
-
used.add(conditions[i]);
|
|
880
|
-
cssText += `${conditions[i]} {`;
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
if (selectors.length && !used.has(selectors)) {
|
|
884
|
-
used.add(selectors);
|
|
885
|
-
cssText += `${selectors.map((s) => s.replace("& ", ""))} {`;
|
|
886
|
-
}
|
|
887
|
-
let value2 = data;
|
|
888
|
-
if (typeof value2 === "number") {
|
|
889
|
-
const shouldAddPx = !(value2 === 0 || unitlessProperties.has(name) || isVariableLike);
|
|
890
|
-
if (shouldAddPx) {
|
|
891
|
-
value2 = `${value2}px`;
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
if (isAtRuleLike) {
|
|
895
|
-
name = `${name} `;
|
|
896
|
-
} else if (isVariableLike) {
|
|
897
|
-
name = `${name}: `;
|
|
898
|
-
} else {
|
|
899
|
-
name = `${(0, import_shared6.hypenateProperty)(name)}: `;
|
|
900
|
-
}
|
|
901
|
-
cssText += `${name + String(value2)};
|
|
902
|
-
`;
|
|
903
|
-
return cssText;
|
|
904
|
-
};
|
|
905
|
-
const parse = (style, selectors, conditions) => {
|
|
906
|
-
let cssText = "";
|
|
907
|
-
for (const name in style) {
|
|
908
|
-
const isAtRuleLike = name[0] === "@";
|
|
909
|
-
const isVariableLike = !isAtRuleLike && name.startsWith("--");
|
|
910
|
-
const rules = isAtRuleLike && Array.isArray(style[name]) ? style[name] : [style[name]];
|
|
911
|
-
for (const data of rules) {
|
|
912
|
-
const isObjectLike = typeof data === "object" && data && data.toString === toString;
|
|
913
|
-
if (!isObjectLike) {
|
|
914
|
-
cssText = write(cssText, selectors, conditions, name, data, isAtRuleLike, isVariableLike);
|
|
915
|
-
continue;
|
|
916
|
-
}
|
|
917
|
-
if (used.has(selectors)) {
|
|
918
|
-
used.delete(selectors);
|
|
919
|
-
cssText += "}";
|
|
920
|
-
}
|
|
921
|
-
let usedName = Object(name);
|
|
922
|
-
let nextSelectors;
|
|
923
|
-
if (isAtRuleLike) {
|
|
924
|
-
if (selectors.length && name.includes("@scope") && name.includes("&")) {
|
|
925
|
-
const resolvedSelectors = getResolvedSelectors(selectors, parseSelectors(name));
|
|
926
|
-
usedName = Object(resolvedSelectors[0]);
|
|
927
|
-
}
|
|
928
|
-
nextSelectors = selectors;
|
|
929
|
-
cssText += parse(data, nextSelectors, conditions.concat(usedName));
|
|
930
|
-
} else {
|
|
931
|
-
const nestedSelectors = parseSelectors(name);
|
|
932
|
-
nextSelectors = selectors.length ? getResolvedSelectors(selectors, nestedSelectors) : nestedSelectors;
|
|
933
|
-
cssText += parse(data, nextSelectors, conditions);
|
|
934
|
-
}
|
|
935
|
-
if (used.has(usedName)) {
|
|
936
|
-
used.delete(usedName);
|
|
937
|
-
cssText += "}\n";
|
|
938
|
-
}
|
|
939
|
-
if (used.has(nextSelectors)) {
|
|
940
|
-
used.delete(nextSelectors);
|
|
941
|
-
cssText += "}\n";
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
return cssText;
|
|
946
|
-
};
|
|
947
|
-
return parse(value, [], []);
|
|
948
|
-
}
|
|
949
|
-
function parseSelectors(selector) {
|
|
950
|
-
const result = [];
|
|
951
|
-
let parenCount = 0;
|
|
952
|
-
let currentSelector = "";
|
|
953
|
-
let inEscape = false;
|
|
954
|
-
for (let i = 0; i < selector.length; i++) {
|
|
955
|
-
const char = selector[i];
|
|
956
|
-
if (char === "\\" && !inEscape) {
|
|
957
|
-
inEscape = true;
|
|
958
|
-
currentSelector += char;
|
|
959
|
-
continue;
|
|
960
|
-
}
|
|
961
|
-
if (inEscape) {
|
|
962
|
-
inEscape = false;
|
|
963
|
-
currentSelector += char;
|
|
964
|
-
continue;
|
|
965
|
-
}
|
|
966
|
-
if (char === "(") {
|
|
967
|
-
parenCount++;
|
|
968
|
-
} else if (char === ")") {
|
|
969
|
-
parenCount--;
|
|
970
|
-
}
|
|
971
|
-
if (char === "," && parenCount === 0) {
|
|
972
|
-
result.push(currentSelector.trim());
|
|
973
|
-
currentSelector = "";
|
|
974
|
-
} else {
|
|
975
|
-
currentSelector += char;
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
if (currentSelector) {
|
|
979
|
-
result.push(currentSelector.trim());
|
|
980
|
-
}
|
|
981
|
-
return result;
|
|
982
|
-
}
|
|
983
|
-
var parentSelectorRegex = /&/g;
|
|
984
|
-
var descendantSelectorRegex = /[ +>|~]/g;
|
|
985
|
-
var surroundedRegex = /&.*&/g;
|
|
986
|
-
var getResolvedSelectors = (parentSelectors, nestedSelectors) => {
|
|
987
|
-
const resolved = [];
|
|
988
|
-
parentSelectors.forEach((parentSelector) => {
|
|
989
|
-
resolved.push(
|
|
990
|
-
...nestedSelectors.map((selector) => {
|
|
991
|
-
if (!selector.includes("&")) return parentSelector + " " + selector;
|
|
992
|
-
return selector.replace(
|
|
993
|
-
parentSelectorRegex,
|
|
994
|
-
descendantSelectorRegex.test(parentSelector) && surroundedRegex.test(selector) ? `:is(${parentSelector})` : parentSelector
|
|
995
|
-
);
|
|
996
|
-
})
|
|
997
|
-
);
|
|
998
|
-
});
|
|
999
|
-
return resolved;
|
|
1000
|
-
};
|
|
1001
|
-
|
|
1002
|
-
// src/global-fontface.ts
|
|
1003
|
-
var GlobalFontface = class {
|
|
1004
|
-
constructor(options) {
|
|
1005
|
-
this.options = options;
|
|
1006
|
-
const { globalFontface = {} } = options;
|
|
1007
|
-
this.names = Object.keys(globalFontface);
|
|
1008
|
-
}
|
|
1009
|
-
names;
|
|
1010
|
-
isEmpty() {
|
|
1011
|
-
return this.names.length === 0;
|
|
1012
|
-
}
|
|
1013
|
-
toString() {
|
|
1014
|
-
const { globalFontface = {} } = this.options;
|
|
1015
|
-
return stringifyGlobalFontface(globalFontface);
|
|
1016
|
-
}
|
|
1017
|
-
};
|
|
1018
|
-
var stringifyGlobalFontface = (globalFontface) => {
|
|
1019
|
-
if (!globalFontface) return "";
|
|
1020
|
-
const lines = [];
|
|
1021
|
-
Object.entries(globalFontface).forEach(([key, value]) => {
|
|
1022
|
-
const _value = Array.isArray(value) ? value : [value];
|
|
1023
|
-
_value.forEach((v) => {
|
|
1024
|
-
lines.push(stringifyFontface(key, v));
|
|
1025
|
-
});
|
|
1026
|
-
});
|
|
1027
|
-
return lines.join("\n\n");
|
|
1028
|
-
};
|
|
1029
|
-
function stringifyFontface(fontFamily, config) {
|
|
1030
|
-
return `@font-face {
|
|
1031
|
-
font-family: ${fontFamily};
|
|
1032
|
-
${stringify(config)}
|
|
1033
|
-
}`;
|
|
1034
|
-
}
|
|
1035
|
-
|
|
1036
|
-
// src/global-position-try.ts
|
|
1037
|
-
var GlobalPositionTry = class {
|
|
1038
|
-
constructor(opts) {
|
|
1039
|
-
this.opts = opts;
|
|
1040
|
-
this.names = Object.keys(opts.globalPositionTry ?? {});
|
|
1041
|
-
}
|
|
1042
|
-
names;
|
|
1043
|
-
isEmpty() {
|
|
1044
|
-
return this.names.length === 0;
|
|
1045
|
-
}
|
|
1046
|
-
toString() {
|
|
1047
|
-
return stringifyGlobalPositionTry(this.opts.globalPositionTry ?? {});
|
|
1048
|
-
}
|
|
1049
|
-
};
|
|
1050
|
-
var stringifyGlobalPositionTry = (dfns) => {
|
|
1051
|
-
if (!dfns) return "";
|
|
1052
|
-
const lines = [];
|
|
1053
|
-
Object.entries(dfns).forEach(([key, value]) => {
|
|
1054
|
-
const _value = Array.isArray(value) ? value : [value];
|
|
1055
|
-
_value.forEach((v) => {
|
|
1056
|
-
lines.push(stringifyPositionTry(key, v));
|
|
1057
|
-
});
|
|
1058
|
-
});
|
|
1059
|
-
return lines.join("\n\n");
|
|
1060
|
-
};
|
|
1061
|
-
var ident = (key) => key.startsWith("--") ? key : `--${key}`;
|
|
1062
|
-
function stringifyPositionTry(key, config) {
|
|
1063
|
-
return `@position-try ${ident(key)} {
|
|
1064
|
-
${stringify(config)}
|
|
1065
|
-
}`;
|
|
1066
|
-
}
|
|
1067
|
-
|
|
1068
|
-
// src/global-vars.ts
|
|
1069
|
-
var import_outdent2 = require("outdent");
|
|
1070
|
-
var GlobalVars = class {
|
|
1071
|
-
constructor(options) {
|
|
1072
|
-
this.options = options;
|
|
1073
|
-
const { globalVars = {} } = options;
|
|
1074
|
-
this.keys = new Set(Object.keys(globalVars));
|
|
1075
|
-
const arr = Array.from(this.keys);
|
|
1076
|
-
this.names = arr.map((v) => `${v.slice(2)}`);
|
|
1077
|
-
this.vars = arr.map((v) => `var(${v})`);
|
|
1078
|
-
}
|
|
1079
|
-
keys;
|
|
1080
|
-
vars;
|
|
1081
|
-
names;
|
|
1082
|
-
isEmpty() {
|
|
1083
|
-
return this.keys.size === 0;
|
|
1084
|
-
}
|
|
1085
|
-
toString() {
|
|
1086
|
-
const { globalVars = {}, cssVarRoot } = this.options;
|
|
1087
|
-
return stringifyGlobalVars(globalVars, cssVarRoot);
|
|
1088
|
-
}
|
|
1089
|
-
};
|
|
1090
|
-
var stringifyGlobalVars = (globalVars, cssVarRoot) => {
|
|
1091
|
-
if (!globalVars) return "";
|
|
1092
|
-
const decls = [];
|
|
1093
|
-
const vars = { [cssVarRoot]: {} };
|
|
1094
|
-
const base = vars[cssVarRoot];
|
|
1095
|
-
Object.entries(globalVars).forEach(([key, value]) => {
|
|
1096
|
-
if (typeof value === "string") {
|
|
1097
|
-
base[key] = value;
|
|
1098
|
-
return;
|
|
1099
|
-
}
|
|
1100
|
-
const css = stringifyProperty(key, value);
|
|
1101
|
-
decls.push(css);
|
|
1102
|
-
});
|
|
1103
|
-
const lines = [];
|
|
1104
|
-
lines.push(stringify(vars));
|
|
1105
|
-
lines.push(...decls);
|
|
1106
|
-
return lines.join("\n\n");
|
|
1107
|
-
};
|
|
1108
|
-
function stringifyProperty(key, config) {
|
|
1109
|
-
return import_outdent2.outdent`@property ${key} {
|
|
1110
|
-
syntax: '${config.syntax}';
|
|
1111
|
-
inherits: ${config.inherits};
|
|
1112
|
-
initial-value: ${config.initialValue ?? "initial"};
|
|
1113
|
-
}`;
|
|
1114
|
-
}
|
|
1115
|
-
|
|
1116
|
-
// src/rule-processor.ts
|
|
1117
|
-
var import_shared7 = require("@bamboocss/shared");
|
|
1118
|
-
var RuleProcessor = class {
|
|
1119
|
-
constructor(context) {
|
|
1120
|
-
this.context = context;
|
|
1121
|
-
this.encoder = context.encoder;
|
|
1122
|
-
this.decoder = context.decoder;
|
|
1123
|
-
this.sheet = context.createSheet();
|
|
1124
|
-
}
|
|
1125
|
-
encoder;
|
|
1126
|
-
decoder;
|
|
1127
|
-
sheet;
|
|
1128
|
-
getParamsOrThrow() {
|
|
1129
|
-
const isReady = Boolean(this.encoder && this.decoder && this.sheet);
|
|
1130
|
-
if (!isReady) {
|
|
1131
|
-
throw new import_shared7.BambooError("MISSING_PARAMS", "RuleProcessor is missing params, please call `clone` first");
|
|
1132
|
-
}
|
|
1133
|
-
return {
|
|
1134
|
-
encoder: this.encoder,
|
|
1135
|
-
decoder: this.decoder,
|
|
1136
|
-
sheet: this.sheet
|
|
1137
|
-
};
|
|
1138
|
-
}
|
|
1139
|
-
clone() {
|
|
1140
|
-
this.encoder = this.context.encoder.clone();
|
|
1141
|
-
this.decoder = this.context.decoder.clone();
|
|
1142
|
-
this.sheet = this.context.createSheet();
|
|
1143
|
-
return this;
|
|
1144
|
-
}
|
|
1145
|
-
toCss(options) {
|
|
1146
|
-
const { decoder, sheet } = this.getParamsOrThrow();
|
|
1147
|
-
sheet.processDecoder(decoder);
|
|
1148
|
-
return sheet.toCss(options);
|
|
1149
|
-
}
|
|
1150
|
-
css(styles) {
|
|
1151
|
-
const { encoder, decoder } = this.getParamsOrThrow();
|
|
1152
|
-
encoder.processAtomic(styles);
|
|
1153
|
-
decoder.collect(encoder);
|
|
1154
|
-
return {
|
|
1155
|
-
styles,
|
|
1156
|
-
getClassNames: () => Array.from(decoder.classNames.keys()),
|
|
1157
|
-
toCss: this.toCss.bind(this)
|
|
1158
|
-
};
|
|
1159
|
-
}
|
|
1160
|
-
grouped(styles) {
|
|
1161
|
-
const { encoder, decoder } = this.getParamsOrThrow();
|
|
1162
|
-
encoder.processGrouped(styles);
|
|
1163
|
-
decoder.collect(encoder);
|
|
1164
|
-
const groupedResults = Array.from(decoder.grouped);
|
|
1165
|
-
return {
|
|
1166
|
-
styles,
|
|
1167
|
-
getClassNames: () => groupedResults.map((r) => r.className),
|
|
1168
|
-
toCss: this.toCss.bind(this)
|
|
1169
|
-
};
|
|
1170
|
-
}
|
|
1171
|
-
cva(recipeConfig) {
|
|
1172
|
-
const { encoder, decoder } = this.getParamsOrThrow();
|
|
1173
|
-
encoder.processAtomicRecipe(recipeConfig);
|
|
1174
|
-
decoder.collect(encoder);
|
|
1175
|
-
return {
|
|
1176
|
-
config: recipeConfig,
|
|
1177
|
-
getClassNames: () => Array.from(decoder.classNames.keys()),
|
|
1178
|
-
toCss: this.toCss.bind(this)
|
|
1179
|
-
};
|
|
1180
|
-
}
|
|
1181
|
-
sva(recipeConfig) {
|
|
1182
|
-
const { encoder, decoder } = this;
|
|
1183
|
-
this.getParamsOrThrow();
|
|
1184
|
-
encoder.processAtomicSlotRecipe(recipeConfig);
|
|
1185
|
-
decoder.collect(encoder);
|
|
1186
|
-
return {
|
|
1187
|
-
config: recipeConfig,
|
|
1188
|
-
getClassNames: () => Array.from(decoder.classNames.keys()),
|
|
1189
|
-
toCss: this.toCss.bind(this)
|
|
1190
|
-
};
|
|
1191
|
-
}
|
|
1192
|
-
recipe(name, variants = {}) {
|
|
1193
|
-
const { encoder, decoder } = this;
|
|
1194
|
-
this.getParamsOrThrow();
|
|
1195
|
-
encoder.processRecipe(name, variants);
|
|
1196
|
-
decoder.collect(encoder);
|
|
1197
|
-
return {
|
|
1198
|
-
variants,
|
|
1199
|
-
getClassNames: () => Array.from(decoder.classNames.keys()),
|
|
1200
|
-
toCss: this.toCss.bind(this)
|
|
1201
|
-
};
|
|
1202
|
-
}
|
|
1203
|
-
};
|
|
1204
|
-
|
|
1205
|
-
// src/hooks-api.ts
|
|
1206
|
-
var HooksApi = class {
|
|
1207
|
-
constructor(ctx) {
|
|
1208
|
-
this.ctx = ctx;
|
|
1209
|
-
this.processor = new RuleProcessor(ctx);
|
|
1210
|
-
}
|
|
1211
|
-
processor;
|
|
1212
|
-
get config() {
|
|
1213
|
-
return this.ctx.conf.config;
|
|
1214
|
-
}
|
|
1215
|
-
get configPath() {
|
|
1216
|
-
return this.ctx.conf.path;
|
|
1217
|
-
}
|
|
1218
|
-
get configDependencies() {
|
|
1219
|
-
return this.ctx.conf.dependencies;
|
|
1220
|
-
}
|
|
1221
|
-
get classNames() {
|
|
1222
|
-
return this.ctx.utility.classNames;
|
|
1223
|
-
}
|
|
1224
|
-
get generatedClassNames() {
|
|
1225
|
-
return this.ctx.decoder.classNames;
|
|
1226
|
-
}
|
|
1227
|
-
};
|
|
1228
|
-
|
|
1229
|
-
// src/import-map.ts
|
|
1230
|
-
var import_shared9 = require("@bamboocss/shared");
|
|
1231
|
-
|
|
1232
|
-
// src/file-matcher.ts
|
|
1233
|
-
var import_shared8 = require("@bamboocss/shared");
|
|
1234
|
-
var cssEntrypointFns = /* @__PURE__ */ new Set(["css", "cva", "sva"]);
|
|
1235
|
-
var FileMatcher = class {
|
|
1236
|
-
constructor(context, opts) {
|
|
1237
|
-
this.context = context;
|
|
1238
|
-
const { value, importMap } = opts;
|
|
1239
|
-
this.importMap = importMap;
|
|
1240
|
-
this.imports = value;
|
|
1241
|
-
this.imports.forEach((result) => {
|
|
1242
|
-
if (result.kind === "namespace") {
|
|
1243
|
-
this.namespaces.set(result.name, result);
|
|
1244
|
-
}
|
|
1245
|
-
});
|
|
1246
|
-
this.assignAliases();
|
|
1247
|
-
this.assignProperties();
|
|
1248
|
-
}
|
|
1249
|
-
imports;
|
|
1250
|
-
namespaces = /* @__PURE__ */ new Map();
|
|
1251
|
-
importMap;
|
|
1252
|
-
cssAliases = /* @__PURE__ */ new Set();
|
|
1253
|
-
cvaAliases = /* @__PURE__ */ new Set();
|
|
1254
|
-
svaAliases = /* @__PURE__ */ new Set();
|
|
1255
|
-
tokenAliases = /* @__PURE__ */ new Set();
|
|
1256
|
-
jsxFactoryAliases = /* @__PURE__ */ new Set();
|
|
1257
|
-
recipeAliases = /* @__PURE__ */ new Set();
|
|
1258
|
-
patternAliases = /* @__PURE__ */ new Set();
|
|
1259
|
-
propertiesMap = /* @__PURE__ */ new Map();
|
|
1260
|
-
functions = /* @__PURE__ */ new Map();
|
|
1261
|
-
components = /* @__PURE__ */ new Map();
|
|
1262
|
-
assignAliases() {
|
|
1263
|
-
const isCssEntrypoint = this.createMatch(this.importMap.css, Array.from(cssEntrypointFns));
|
|
1264
|
-
const isTokensEntrypoint = this.createMatch(this.importMap.tokens, ["token"]);
|
|
1265
|
-
this.imports.forEach((result) => {
|
|
1266
|
-
if (this.isValidRecipe(result.alias)) {
|
|
1267
|
-
this.recipeAliases.add(result.alias);
|
|
1268
|
-
}
|
|
1269
|
-
if (this.isValidPattern(result.alias)) {
|
|
1270
|
-
this.patternAliases.add(result.alias);
|
|
1271
|
-
}
|
|
1272
|
-
if (isCssEntrypoint(result.alias)) {
|
|
1273
|
-
if (result.name === "css") {
|
|
1274
|
-
this.cssAliases.add(result.alias);
|
|
1275
|
-
}
|
|
1276
|
-
if (result.name === "cva") {
|
|
1277
|
-
this.cvaAliases.add(result.alias);
|
|
1278
|
-
}
|
|
1279
|
-
if (result.name === "sva") {
|
|
1280
|
-
this.svaAliases.add(result.alias);
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
if (isTokensEntrypoint(result.alias)) {
|
|
1284
|
-
if (result.name === "token") {
|
|
1285
|
-
this.tokenAliases.add(result.alias);
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
if (result.name === this.context.jsx.factoryName) {
|
|
1289
|
-
this.jsxFactoryAliases.add(result.alias);
|
|
1290
|
-
}
|
|
1291
|
-
if (result.kind === "namespace") {
|
|
1292
|
-
if (this.importMap.pattern.some((m) => result.mod.includes(m))) {
|
|
1293
|
-
this.context.patterns.keys.forEach((pattern) => {
|
|
1294
|
-
this.patternAliases.add(pattern);
|
|
1295
|
-
});
|
|
1296
|
-
}
|
|
1297
|
-
if (this.importMap.recipe.some((m) => result.mod.includes(m))) {
|
|
1298
|
-
this.context.recipes.keys.forEach((recipe) => {
|
|
1299
|
-
this.recipeAliases.add(recipe);
|
|
1300
|
-
});
|
|
1301
|
-
}
|
|
1302
|
-
}
|
|
1303
|
-
});
|
|
1304
|
-
}
|
|
1305
|
-
assignProperties() {
|
|
1306
|
-
this.context.jsx.nodes.forEach((node) => {
|
|
1307
|
-
const aliases = this.getAliases(node.jsxName);
|
|
1308
|
-
aliases.forEach((alias) => {
|
|
1309
|
-
node.props?.forEach((prop) => this.propertiesMap.set(prop, true));
|
|
1310
|
-
this.functions.set(node.baseName, this.propertiesMap);
|
|
1311
|
-
this.functions.set(alias, this.propertiesMap);
|
|
1312
|
-
this.components.set(alias, this.propertiesMap);
|
|
1313
|
-
});
|
|
1314
|
-
});
|
|
1315
|
-
}
|
|
1316
|
-
isEmpty = () => {
|
|
1317
|
-
return this.imports.length === 0;
|
|
1318
|
-
};
|
|
1319
|
-
toString = () => {
|
|
1320
|
-
return this.imports.map((item) => item.alias).join(", ");
|
|
1321
|
-
};
|
|
1322
|
-
find = (id) => {
|
|
1323
|
-
return this.imports.find((o) => o.alias === id);
|
|
1324
|
-
};
|
|
1325
|
-
createMatch = (mods, keys2) => {
|
|
1326
|
-
const matchingImports = this.imports.filter((o) => {
|
|
1327
|
-
const isFromMod = mods.some((m) => o.mod.includes(m) || o.importMapValue?.includes(m));
|
|
1328
|
-
const isOneOfKeys = o.kind === "namespace" ? true : keys2.includes(o.name);
|
|
1329
|
-
return isFromMod && isOneOfKeys;
|
|
1330
|
-
});
|
|
1331
|
-
return (0, import_shared8.memo)((id) => {
|
|
1332
|
-
return !!matchingImports.find((mod) => {
|
|
1333
|
-
if (mod.kind === "namespace") {
|
|
1334
|
-
return keys2.includes(id.replace(`${mod.alias}.`, ""));
|
|
1335
|
-
}
|
|
1336
|
-
return mod.alias === id || mod.name === id;
|
|
1337
|
-
});
|
|
1338
|
-
});
|
|
1339
|
-
};
|
|
1340
|
-
match = (id) => {
|
|
1341
|
-
return !!this.find(id);
|
|
1342
|
-
};
|
|
1343
|
-
getName = (id) => {
|
|
1344
|
-
return this.find(id)?.name || id;
|
|
1345
|
-
};
|
|
1346
|
-
getAliases = (id) => {
|
|
1347
|
-
return this.imports.filter((o) => o.name === id).map((o) => o.alias || id);
|
|
1348
|
-
};
|
|
1349
|
-
_patternsMatcher;
|
|
1350
|
-
isValidPattern = (id) => {
|
|
1351
|
-
this._patternsMatcher ||= this.createMatch(this.importMap.pattern, this.context.patterns.keys);
|
|
1352
|
-
return this._patternsMatcher(id);
|
|
1353
|
-
};
|
|
1354
|
-
_recipesMatcher;
|
|
1355
|
-
isValidRecipe = (id) => {
|
|
1356
|
-
this._recipesMatcher ||= this.createMatch(this.importMap.recipe, this.context.recipes.keys);
|
|
1357
|
-
return this._recipesMatcher(id);
|
|
1358
|
-
};
|
|
1359
|
-
isRawFn = (fnName) => {
|
|
1360
|
-
const name = fnName.split(".raw")[0] ?? "";
|
|
1361
|
-
const isCssOrAlias = name === "css" || this.cssAliases.has(name) || this.cvaAliases.has(name) || this.svaAliases.has(name);
|
|
1362
|
-
return isCssOrAlias || this.isValidPattern(name) || this.isValidRecipe(name);
|
|
1363
|
-
};
|
|
1364
|
-
isNamespaced = (fnName) => {
|
|
1365
|
-
return this.namespaces.has(fnName.split(".")[0]);
|
|
1366
|
-
};
|
|
1367
|
-
normalizeFnName = (fnName) => {
|
|
1368
|
-
let name = fnName;
|
|
1369
|
-
if (this.isNamespaced(fnName)) {
|
|
1370
|
-
name = name.split(".").slice(1).join(".");
|
|
1371
|
-
}
|
|
1372
|
-
if (this.isRawFn(name)) return name.replace(".raw", "");
|
|
1373
|
-
return name;
|
|
1374
|
-
};
|
|
1375
|
-
isAliasFnName = (0, import_shared8.memo)((fnName) => {
|
|
1376
|
-
return this.cvaAliases.has(fnName) || this.cssAliases.has(fnName) || this.svaAliases.has(fnName) || this.tokenAliases.has(fnName) || this.isJsxFactory(fnName);
|
|
1377
|
-
});
|
|
1378
|
-
isTokenAlias = (fnName) => {
|
|
1379
|
-
return this.tokenAliases.has(fnName);
|
|
1380
|
-
};
|
|
1381
|
-
matchFn = (0, import_shared8.memo)((fnName) => {
|
|
1382
|
-
if (this.recipeAliases.has(fnName) || this.patternAliases.has(fnName)) return true;
|
|
1383
|
-
if (this.isAliasFnName(fnName) || this.isRawFn(fnName)) return true;
|
|
1384
|
-
if (this.functions.has(fnName)) return true;
|
|
1385
|
-
const [namespace, identifier] = fnName.split(".");
|
|
1386
|
-
const ns = this.namespaces.get(namespace);
|
|
1387
|
-
if (ns) {
|
|
1388
|
-
if (this.importMap.css.some((m) => ns.mod.includes(m)) && cssEntrypointFns.has(identifier)) return true;
|
|
1389
|
-
if (this.importMap.tokens.some((m) => ns.mod.includes(m)) && identifier === "token") return true;
|
|
1390
|
-
if (this.importMap.recipe.some((m) => ns.mod.includes(m)) && this.recipeAliases.has(identifier)) return true;
|
|
1391
|
-
if (this.importMap.pattern.some((m) => ns.mod.includes(m)) && this.patternAliases.has(identifier)) return true;
|
|
1392
|
-
return this.functions.has(identifier);
|
|
1393
|
-
}
|
|
1394
|
-
return false;
|
|
1395
|
-
});
|
|
1396
|
-
isJsxFactory = (0, import_shared8.memo)((tagName) => {
|
|
1397
|
-
const { jsx } = this.context;
|
|
1398
|
-
if (!jsx.isEnabled) return false;
|
|
1399
|
-
for (const alias of this.jsxFactoryAliases) {
|
|
1400
|
-
if (tagName.startsWith(alias)) return true;
|
|
1401
|
-
}
|
|
1402
|
-
const [namespace, identifier] = tagName.split(".");
|
|
1403
|
-
const ns = this.namespaces.get(namespace);
|
|
1404
|
-
if (ns && this.importMap.jsx.some((m) => ns.mod.includes(m)) && identifier === this.context.jsx.factoryName) {
|
|
1405
|
-
return true;
|
|
1406
|
-
}
|
|
1407
|
-
});
|
|
1408
|
-
isBambooComponent = (0, import_shared8.memo)((tagName) => {
|
|
1409
|
-
if (!tagName) return false;
|
|
1410
|
-
const { jsx } = this.context;
|
|
1411
|
-
return this.components.has(tagName) || this.isJsxFactory(tagName) || jsx.isJsxTagRecipe(tagName) || jsx.isJsxTagPattern(tagName);
|
|
1412
|
-
});
|
|
1413
|
-
matchTag = (0, import_shared8.memo)((tagName) => {
|
|
1414
|
-
return this.isBambooComponent(tagName) || isUpperCase(tagName);
|
|
1415
|
-
});
|
|
1416
|
-
matchTagProp = (0, import_shared8.memo)((tagName, propName) => {
|
|
1417
|
-
const { jsx, isValidProperty } = this.context;
|
|
1418
|
-
switch (jsx.styleProps) {
|
|
1419
|
-
case "all":
|
|
1420
|
-
return Boolean(this.components.get(tagName)?.has(propName)) || isValidProperty(propName) || this.propertiesMap.has(propName) || jsx.isRecipeOrPatternProp(tagName, propName) || propName.endsWith("Css");
|
|
1421
|
-
case "minimal":
|
|
1422
|
-
return propName === "css" || propName.endsWith("Css") || jsx.isRecipeOrPatternProp(tagName, propName);
|
|
1423
|
-
case "none":
|
|
1424
|
-
return jsx.isRecipeOrPatternProp(tagName, propName);
|
|
1425
|
-
default:
|
|
1426
|
-
return false;
|
|
1427
|
-
}
|
|
1428
|
-
});
|
|
1429
|
-
};
|
|
1430
|
-
var isUpperCase = (value) => value[0] === value[0]?.toUpperCase();
|
|
1431
|
-
|
|
1432
|
-
// src/import-map.ts
|
|
1433
|
-
var ImportMap = class {
|
|
1434
|
-
constructor(context) {
|
|
1435
|
-
this.context = context;
|
|
1436
|
-
const { jsx } = this.context;
|
|
1437
|
-
this.outdir = this.getOutdir();
|
|
1438
|
-
const importMap = this.buildImportMap(context.config.importMap);
|
|
1439
|
-
this.matchers.css = this.createMatcher(importMap.css, ["css", "cva", "sva"]);
|
|
1440
|
-
this.matchers.tokens = this.createMatcher(importMap.tokens, ["token"]);
|
|
1441
|
-
this.matchers.recipe = this.createMatcher(importMap.recipe);
|
|
1442
|
-
this.matchers.pattern = this.createMatcher(importMap.pattern);
|
|
1443
|
-
if (jsx.isEnabled) {
|
|
1444
|
-
this.matchers.jsx = this.createMatcher(importMap.jsx, jsx.names);
|
|
1445
|
-
}
|
|
1446
|
-
this.value = importMap;
|
|
1447
|
-
}
|
|
1448
|
-
value;
|
|
1449
|
-
matchers = {};
|
|
1450
|
-
outdir;
|
|
1451
|
-
/**
|
|
1452
|
-
* Normalize one/many import map inputs to a single import map output with absolute paths.
|
|
1453
|
-
* @example
|
|
1454
|
-
* ```ts
|
|
1455
|
-
* importMap: '@acme/org'
|
|
1456
|
-
* ```
|
|
1457
|
-
*
|
|
1458
|
-
* will be normalized to
|
|
1459
|
-
* ```ts
|
|
1460
|
-
* {
|
|
1461
|
-
* css: ['@acme/org/css'],
|
|
1462
|
-
* recipe: ['@acme/org/recipes'],
|
|
1463
|
-
* pattern: ['@acme/org/patterns'],
|
|
1464
|
-
* jsx: ['@acme/org/jsx'],
|
|
1465
|
-
* tokens: ['@acme/org/tokens'],
|
|
1466
|
-
* }
|
|
1467
|
-
* ```
|
|
1468
|
-
*
|
|
1469
|
-
* @exammple
|
|
1470
|
-
* importMap: ['@acme/org', '@foo/org', '@bar/org']
|
|
1471
|
-
* ```
|
|
1472
|
-
*
|
|
1473
|
-
* will be normalized to
|
|
1474
|
-
* ```ts
|
|
1475
|
-
* {
|
|
1476
|
-
* css: ['@acme/org/css', '@foo/org/css', '@bar/org/css'],
|
|
1477
|
-
* recipe: ['@acme/org/recipes', '@foo/org/recipes', '@bar/org/recipes'],
|
|
1478
|
-
* pattern: ['@acme/org/patterns', '@foo/org/patterns', '@bar/org/patterns'],
|
|
1479
|
-
* jsx: ['@acme/org/jsx', '@foo/org/jsx', '@bar/org/jsx'],
|
|
1480
|
-
* tokens: ['@acme/org/tokens', '@foo/org/tokens', '@bar/org/tokens'],
|
|
1481
|
-
* }
|
|
1482
|
-
* ```
|
|
1483
|
-
*/
|
|
1484
|
-
buildImportMap = (option) => {
|
|
1485
|
-
const output = { css: [], recipe: [], pattern: [], jsx: [], tokens: [] };
|
|
1486
|
-
const inputs = asArray(option);
|
|
1487
|
-
inputs.forEach((input) => {
|
|
1488
|
-
const normalized = this.normalize(input);
|
|
1489
|
-
output.css.push(...normalized.css);
|
|
1490
|
-
output.recipe.push(...normalized.recipe);
|
|
1491
|
-
output.pattern.push(...normalized.pattern);
|
|
1492
|
-
output.tokens.push(...normalized.tokens);
|
|
1493
|
-
if (normalized.jsx) output.jsx.push(...normalized.jsx);
|
|
1494
|
-
});
|
|
1495
|
-
return output;
|
|
1496
|
-
};
|
|
1497
|
-
fromString = (map) => {
|
|
1498
|
-
return {
|
|
1499
|
-
css: [[map, "css"].join("/")],
|
|
1500
|
-
recipe: [[map, "recipes"].join("/")],
|
|
1501
|
-
pattern: [[map, "patterns"].join("/")],
|
|
1502
|
-
jsx: [[map, "jsx"].join("/")],
|
|
1503
|
-
tokens: [[map, "tokens"].join("/")]
|
|
1504
|
-
};
|
|
1505
|
-
};
|
|
1506
|
-
fromInput = (map) => {
|
|
1507
|
-
const { css, recipes, patterns, jsx, tokens } = map ?? {};
|
|
1508
|
-
return {
|
|
1509
|
-
css: css ? asArray(css) : [[this.outdir, "css"].join("/")],
|
|
1510
|
-
recipe: recipes ? asArray(recipes) : [[this.outdir, "recipes"].join("/")],
|
|
1511
|
-
pattern: patterns ? asArray(patterns) : [[this.outdir, "patterns"].join("/")],
|
|
1512
|
-
jsx: jsx ? asArray(jsx) : [[this.outdir, "jsx"].join("/")],
|
|
1513
|
-
tokens: tokens ? asArray(tokens) : [[this.outdir, "tokens"].join("/")]
|
|
1514
|
-
};
|
|
1515
|
-
};
|
|
1516
|
-
getOutdir = () => {
|
|
1517
|
-
const { outdir } = this.context.config;
|
|
1518
|
-
const split = outdir.split("/");
|
|
1519
|
-
return split[split.length - 1];
|
|
1520
|
-
};
|
|
1521
|
-
normalize = (map) => {
|
|
1522
|
-
if ((0, import_shared9.isString)(map)) return this.fromString(map);
|
|
1523
|
-
return this.fromInput(map);
|
|
1524
|
-
};
|
|
1525
|
-
createMatcher = (mods, values) => {
|
|
1526
|
-
const regex = values ? new RegExp(`^(${values.join("|")})$`) : /.*/;
|
|
1527
|
-
const match3 = (value) => regex.test(value);
|
|
1528
|
-
return { mods, regex, match: match3 };
|
|
1529
|
-
};
|
|
1530
|
-
match = (result, resolveTsPath) => {
|
|
1531
|
-
if (!result) return false;
|
|
1532
|
-
for (const { regex, mods } of Object.values(this.matchers)) {
|
|
1533
|
-
if (result.kind !== "namespace" && !regex.test(result.name)) continue;
|
|
1534
|
-
if (mods.some((m) => result.mod.includes(m))) {
|
|
1535
|
-
return true;
|
|
1536
|
-
}
|
|
1537
|
-
const resolvedMod = resolveTsPath?.(result.mod);
|
|
1538
|
-
for (const mod of mods) {
|
|
1539
|
-
const absMod = [this.context.config.cwd, mod].join("/").replaceAll("\\", "/");
|
|
1540
|
-
if (resolvedMod?.includes(absMod) || resolvedMod === mod) {
|
|
1541
|
-
result.importMapValue = resolvedMod;
|
|
1542
|
-
return true;
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
1546
|
-
return false;
|
|
1547
|
-
};
|
|
1548
|
-
file = (results) => {
|
|
1549
|
-
return new FileMatcher(this.context, { importMap: this.value, value: results });
|
|
1550
|
-
};
|
|
1551
|
-
};
|
|
1552
|
-
var asArray = (value) => Array.isArray(value) ? value : [value];
|
|
1553
|
-
|
|
1554
|
-
// src/jsx.ts
|
|
1555
|
-
var import_shared10 = require("@bamboocss/shared");
|
|
1556
|
-
var JsxEngine = class {
|
|
1557
|
-
constructor(context) {
|
|
1558
|
-
this.context = context;
|
|
1559
|
-
this.nodes = [...context.patterns.details, ...context.recipes.details];
|
|
1560
|
-
this.names = [this.factoryName, ...this.nodes.map((node) => node.jsxName)];
|
|
1561
|
-
this.assignRecipeMatcher();
|
|
1562
|
-
this.assignPatternMatcher();
|
|
1563
|
-
}
|
|
1564
|
-
nodes = [];
|
|
1565
|
-
names = [];
|
|
1566
|
-
recipeMatcher = { string: /* @__PURE__ */ new Set(), regex: [] };
|
|
1567
|
-
recipePropertiesByJsxName = /* @__PURE__ */ new Map();
|
|
1568
|
-
patternMatcher = { string: /* @__PURE__ */ new Set(), regex: [] };
|
|
1569
|
-
patternPropertiesByJsxName = /* @__PURE__ */ new Map();
|
|
1570
|
-
assignRecipeMatcher() {
|
|
1571
|
-
if (!this.isEnabled) return;
|
|
1572
|
-
for (const recipe of this.context.recipes.details) {
|
|
1573
|
-
this.recipePropertiesByJsxName.set(recipe.jsxName, new Set(recipe.props ?? []));
|
|
1574
|
-
recipe.jsx.forEach((jsx) => {
|
|
1575
|
-
if (typeof jsx === "string") {
|
|
1576
|
-
this.recipeMatcher.string.add(jsx);
|
|
1577
|
-
} else {
|
|
1578
|
-
this.recipeMatcher.regex.push(jsx);
|
|
1579
|
-
}
|
|
1580
|
-
});
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
assignPatternMatcher() {
|
|
1584
|
-
if (!this.isEnabled) return;
|
|
1585
|
-
for (const pattern of this.context.patterns.details) {
|
|
1586
|
-
this.patternPropertiesByJsxName.set(pattern.jsxName, new Set(pattern.props ?? []));
|
|
1587
|
-
pattern.jsx.forEach((jsx) => {
|
|
1588
|
-
if (typeof jsx === "string") {
|
|
1589
|
-
this.patternMatcher.string.add(jsx);
|
|
1590
|
-
} else {
|
|
1591
|
-
this.patternMatcher.regex.push(jsx);
|
|
1592
|
-
}
|
|
1593
|
-
});
|
|
1594
|
-
}
|
|
1595
|
-
}
|
|
1596
|
-
get jsxFactory() {
|
|
1597
|
-
return this.context.config.jsxFactory ?? "styled";
|
|
1598
|
-
}
|
|
1599
|
-
get styleProps() {
|
|
1600
|
-
return this.context.config.jsxStyleProps ?? "all";
|
|
1601
|
-
}
|
|
1602
|
-
get framework() {
|
|
1603
|
-
return this.context.config.jsxFramework;
|
|
1604
|
-
}
|
|
1605
|
-
get isEnabled() {
|
|
1606
|
-
return this.framework != null;
|
|
1607
|
-
}
|
|
1608
|
-
get factoryName() {
|
|
1609
|
-
return this.jsxFactory;
|
|
1610
|
-
}
|
|
1611
|
-
get upperName() {
|
|
1612
|
-
return (0, import_shared10.capitalize)(this.jsxFactory);
|
|
1613
|
-
}
|
|
1614
|
-
get typeName() {
|
|
1615
|
-
return `HTML${(0, import_shared10.capitalize)(this.jsxFactory)}Props`;
|
|
1616
|
-
}
|
|
1617
|
-
get variantName() {
|
|
1618
|
-
return `${(0, import_shared10.capitalize)(this.jsxFactory)}VariantProps`;
|
|
1619
|
-
}
|
|
1620
|
-
get componentName() {
|
|
1621
|
-
return `${(0, import_shared10.capitalize)(this.jsxFactory)}Component`;
|
|
1622
|
-
}
|
|
1623
|
-
isJsxFactory = (name) => {
|
|
1624
|
-
const isFactory = name === this.factoryName;
|
|
1625
|
-
if (isFactory) return true;
|
|
1626
|
-
const [_namespace, identifier] = name.split(".");
|
|
1627
|
-
return identifier === this.factoryName;
|
|
1628
|
-
};
|
|
1629
|
-
isJsxTagRecipe = (0, import_shared10.memo)((tagName) => {
|
|
1630
|
-
return this.recipeMatcher.string.has(tagName) || this.recipeMatcher.regex.some((regex) => regex.test(tagName));
|
|
1631
|
-
});
|
|
1632
|
-
isJsxTagPattern = (0, import_shared10.memo)((tagName) => {
|
|
1633
|
-
return this.patternMatcher.string.has(tagName) || this.patternMatcher.regex.some((regex) => regex.test(tagName));
|
|
1634
|
-
});
|
|
1635
|
-
isRecipeOrPatternProp = (0, import_shared10.memo)((tagName, propName) => {
|
|
1636
|
-
if (this.isJsxTagRecipe(tagName)) {
|
|
1637
|
-
const recipeList = this.context.recipes.filter(tagName);
|
|
1638
|
-
return recipeList.some((recipe) => this.recipePropertiesByJsxName.get(recipe.jsxName)?.has(propName));
|
|
1639
|
-
}
|
|
1640
|
-
if (this.isJsxTagPattern(tagName)) {
|
|
1641
|
-
const patternList = this.context.patterns.filter(tagName);
|
|
1642
|
-
return patternList.some((pattern) => this.patternPropertiesByJsxName.get(pattern.jsxName)?.has(propName));
|
|
1643
|
-
}
|
|
1644
|
-
return false;
|
|
1645
|
-
});
|
|
1646
|
-
};
|
|
1647
|
-
|
|
1648
|
-
// src/layers.ts
|
|
1649
|
-
var import_shared11 = require("@bamboocss/shared");
|
|
1650
|
-
var import_postcss3 = __toESM(require("postcss"));
|
|
1651
|
-
var Layers = class {
|
|
1652
|
-
constructor(names) {
|
|
1653
|
-
this.names = names;
|
|
1654
|
-
this.root = import_postcss3.default.root();
|
|
1655
|
-
this.reset = import_postcss3.default.atRule({ name: "layer", params: names.reset, nodes: [] });
|
|
1656
|
-
this.base = import_postcss3.default.atRule({ name: "layer", params: names.base, nodes: [] });
|
|
1657
|
-
this.tokens = import_postcss3.default.atRule({ name: "layer", params: names.tokens, nodes: [] });
|
|
1658
|
-
this.recipes = import_postcss3.default.atRule({ name: "layer", params: names.recipes, nodes: [] });
|
|
1659
|
-
this.recipes_base = import_postcss3.default.atRule({ name: "layer", params: "_base", nodes: [] });
|
|
1660
|
-
this.recipes_slots = import_postcss3.default.atRule({ name: "layer", params: names.recipes + ".slots", nodes: [] });
|
|
1661
|
-
this.recipes_slots_base = import_postcss3.default.atRule({ name: "layer", params: "_base", nodes: [] });
|
|
1662
|
-
this.utilities = import_postcss3.default.atRule({ name: "layer", params: names.utilities, nodes: [] });
|
|
1663
|
-
this.compositions = import_postcss3.default.atRule({ name: "layer", params: "compositions", nodes: [] });
|
|
1664
|
-
}
|
|
1665
|
-
root;
|
|
1666
|
-
reset;
|
|
1667
|
-
base;
|
|
1668
|
-
tokens;
|
|
1669
|
-
recipes;
|
|
1670
|
-
recipes_base;
|
|
1671
|
-
recipes_slots;
|
|
1672
|
-
recipes_slots_base;
|
|
1673
|
-
utilities;
|
|
1674
|
-
compositions;
|
|
1675
|
-
utilityRuleMap = /* @__PURE__ */ new Map();
|
|
1676
|
-
getLayerRoot(layer) {
|
|
1677
|
-
const { reset, base, tokens, recipes, recipes_base, recipes_slots, recipes_slots_base, utilities, compositions } = this;
|
|
1678
|
-
switch (layer) {
|
|
1679
|
-
case "base":
|
|
1680
|
-
return base;
|
|
1681
|
-
case "reset":
|
|
1682
|
-
return reset;
|
|
1683
|
-
case "tokens": {
|
|
1684
|
-
return tokens;
|
|
1685
|
-
}
|
|
1686
|
-
case "recipes": {
|
|
1687
|
-
const recipeRoot = import_postcss3.default.root();
|
|
1688
|
-
if (recipes_base.nodes?.length) recipes.prepend(recipes_base);
|
|
1689
|
-
if (recipes_slots_base.nodes?.length) recipes_slots.prepend(recipes_slots_base);
|
|
1690
|
-
if (recipes.nodes?.length) recipeRoot.append(recipes);
|
|
1691
|
-
if (recipes_slots.nodes?.length) recipeRoot.append(recipes_slots);
|
|
1692
|
-
return recipeRoot;
|
|
1693
|
-
}
|
|
1694
|
-
case "utilities": {
|
|
1695
|
-
if (compositions.nodes?.length) utilities.prepend(compositions);
|
|
1696
|
-
this.utilityRuleMap.forEach((rules) => {
|
|
1697
|
-
if (rules.nodes?.length) utilities.append(rules);
|
|
1698
|
-
});
|
|
1699
|
-
return utilities;
|
|
1700
|
-
}
|
|
1701
|
-
default:
|
|
1702
|
-
throw new import_shared11.BambooError("INVALID_LAYER", `Unknown layer: ${layer}`);
|
|
1703
|
-
}
|
|
1704
|
-
}
|
|
1705
|
-
insert() {
|
|
1706
|
-
const { root } = this;
|
|
1707
|
-
const reset = this.getLayerRoot("reset");
|
|
1708
|
-
if (reset.nodes?.length) root.append(reset);
|
|
1709
|
-
const base = this.getLayerRoot("base");
|
|
1710
|
-
if (base.nodes?.length) root.append(base);
|
|
1711
|
-
const tokens = this.getLayerRoot("tokens");
|
|
1712
|
-
if (tokens.nodes?.length) root.append(tokens);
|
|
1713
|
-
const recipes = this.getLayerRoot("recipes");
|
|
1714
|
-
if (recipes.nodes?.length) root.append(recipes);
|
|
1715
|
-
const utilities = this.getLayerRoot("utilities");
|
|
1716
|
-
if (utilities.nodes?.length) root.append(utilities);
|
|
1717
|
-
return root;
|
|
1718
|
-
}
|
|
1719
|
-
get layerNames() {
|
|
1720
|
-
return Object.values(this.names);
|
|
1721
|
-
}
|
|
1722
|
-
get params() {
|
|
1723
|
-
return `@layer ${this.layerNames.join(", ")};`;
|
|
1724
|
-
}
|
|
1725
|
-
};
|
|
1726
|
-
|
|
1727
|
-
// src/path.ts
|
|
1728
|
-
var PathEngine = class {
|
|
1729
|
-
constructor(context) {
|
|
1730
|
-
this.context = context;
|
|
1731
|
-
}
|
|
1732
|
-
get cwd() {
|
|
1733
|
-
return this.context.config.cwd;
|
|
1734
|
-
}
|
|
1735
|
-
get outdir() {
|
|
1736
|
-
return this.context.config.outdir;
|
|
1737
|
-
}
|
|
1738
|
-
getFilePath(file) {
|
|
1739
|
-
return [this.cwd, this.outdir, file].filter(Boolean);
|
|
1740
|
-
}
|
|
1741
|
-
get root() {
|
|
1742
|
-
return this.getFilePath();
|
|
1743
|
-
}
|
|
1744
|
-
get css() {
|
|
1745
|
-
return this.getFilePath("css");
|
|
1746
|
-
}
|
|
1747
|
-
get token() {
|
|
1748
|
-
return this.getFilePath("tokens");
|
|
1749
|
-
}
|
|
1750
|
-
get types() {
|
|
1751
|
-
return this.getFilePath("types");
|
|
1752
|
-
}
|
|
1753
|
-
get recipe() {
|
|
1754
|
-
return this.getFilePath("recipes");
|
|
1755
|
-
}
|
|
1756
|
-
get pattern() {
|
|
1757
|
-
return this.getFilePath("patterns");
|
|
1758
|
-
}
|
|
1759
|
-
get outCss() {
|
|
1760
|
-
return this.getFilePath("styles.css");
|
|
1761
|
-
}
|
|
1762
|
-
get jsx() {
|
|
1763
|
-
return this.getFilePath("jsx");
|
|
1764
|
-
}
|
|
1765
|
-
get themes() {
|
|
1766
|
-
return this.getFilePath("themes");
|
|
1767
|
-
}
|
|
1768
|
-
get specs() {
|
|
1769
|
-
return this.getFilePath("specs");
|
|
1770
|
-
}
|
|
1771
|
-
};
|
|
1772
|
-
|
|
1773
|
-
// src/patterns.ts
|
|
1774
|
-
var import_shared12 = require("@bamboocss/shared");
|
|
1775
|
-
var Patterns = class {
|
|
1776
|
-
constructor(options) {
|
|
1777
|
-
this.options = options;
|
|
1778
|
-
this.patterns = options.config.patterns ?? {};
|
|
1779
|
-
this.details = Object.entries(this.patterns).map(([name, pattern]) => this.createDetail(name, pattern));
|
|
1780
|
-
this.keys = Object.keys(this.patterns);
|
|
1781
|
-
this.utility = options.utility;
|
|
1782
|
-
this.tokens = options.tokens;
|
|
1783
|
-
}
|
|
1784
|
-
patterns;
|
|
1785
|
-
details;
|
|
1786
|
-
keys;
|
|
1787
|
-
utility;
|
|
1788
|
-
tokens;
|
|
1789
|
-
deprecated = /* @__PURE__ */ new Set();
|
|
1790
|
-
createDetail(name, pattern) {
|
|
1791
|
-
const names = this.getNames(name);
|
|
1792
|
-
const jsx = (pattern.jsx ?? []).concat([names.jsxName]);
|
|
1793
|
-
if (pattern.deprecated) {
|
|
1794
|
-
this.deprecated.add(name);
|
|
1795
|
-
}
|
|
1796
|
-
return {
|
|
1797
|
-
...names,
|
|
1798
|
-
props: Object.keys(pattern?.properties ?? {}),
|
|
1799
|
-
blocklistType: pattern?.blocklist ? `| '${pattern.blocklist.join("' | '")}'` : "",
|
|
1800
|
-
config: pattern,
|
|
1801
|
-
type: "pattern",
|
|
1802
|
-
match: (0, import_shared12.createRegex)(jsx),
|
|
1803
|
-
jsx
|
|
1804
|
-
};
|
|
1805
|
-
}
|
|
1806
|
-
getConfig(name) {
|
|
1807
|
-
return this.patterns[name];
|
|
1808
|
-
}
|
|
1809
|
-
transform(name, styles) {
|
|
1810
|
-
const pattern = this.patterns[name];
|
|
1811
|
-
const _styles = (0, import_shared12.getPatternStyles)(pattern, styles);
|
|
1812
|
-
return pattern?.transform?.(_styles, this.options.helpers) ?? {};
|
|
1813
|
-
}
|
|
1814
|
-
getNames(name) {
|
|
1815
|
-
const upperName = (0, import_shared12.capitalize)(name);
|
|
1816
|
-
return {
|
|
1817
|
-
upperName,
|
|
1818
|
-
baseName: name,
|
|
1819
|
-
dashName: (0, import_shared12.dashCase)(name),
|
|
1820
|
-
styleFnName: `get${upperName}Style`,
|
|
1821
|
-
jsxName: this.patterns[name]?.jsxName ?? upperName
|
|
1822
|
-
};
|
|
1823
|
-
}
|
|
1824
|
-
find = (0, import_shared12.memo)((jsxName) => {
|
|
1825
|
-
return this.details.find((node) => node.match.test(jsxName))?.baseName ?? (0, import_shared12.uncapitalize)(jsxName);
|
|
1826
|
-
});
|
|
1827
|
-
filter = (0, import_shared12.memo)((jsxName) => {
|
|
1828
|
-
return this.details.filter((node) => node.match.test(jsxName));
|
|
1829
|
-
});
|
|
1830
|
-
isEmpty() {
|
|
1831
|
-
return this.keys.length === 0;
|
|
1832
|
-
}
|
|
1833
|
-
isDeprecated(name) {
|
|
1834
|
-
return this.deprecated.has(name);
|
|
1835
|
-
}
|
|
1836
|
-
saveOne(name, pattern) {
|
|
1837
|
-
this.patterns[name] = pattern;
|
|
1838
|
-
const detailIndex = this.details.findIndex((detail) => detail.baseName === name);
|
|
1839
|
-
const updated = this.createDetail(name, pattern);
|
|
1840
|
-
if (detailIndex > -1) {
|
|
1841
|
-
this.details[detailIndex] = updated;
|
|
1842
|
-
} else {
|
|
1843
|
-
this.details.push(updated);
|
|
1844
|
-
}
|
|
1845
|
-
}
|
|
1846
|
-
remove(name) {
|
|
1847
|
-
delete this.patterns[name];
|
|
1848
|
-
const detailIndex = this.details.findIndex((detail) => detail.baseName === name);
|
|
1849
|
-
if (detailIndex > -1) {
|
|
1850
|
-
this.details.splice(detailIndex, 1);
|
|
1851
|
-
}
|
|
1852
|
-
}
|
|
1853
|
-
filterDetails(filters) {
|
|
1854
|
-
const patternDiffs = filters?.affecteds?.patterns;
|
|
1855
|
-
return patternDiffs ? this.details.filter((pattern) => patternDiffs.includes(pattern.dashName)) : this.details;
|
|
1856
|
-
}
|
|
1857
|
-
getPropertyValues = (patternName, property) => {
|
|
1858
|
-
const patternConfig = this.getConfig(patternName);
|
|
1859
|
-
if (!patternConfig) return [];
|
|
1860
|
-
const propType = patternConfig.properties?.[property];
|
|
1861
|
-
if (!propType) return;
|
|
1862
|
-
if (propType.type === "enum") {
|
|
1863
|
-
return propType.value;
|
|
1864
|
-
}
|
|
1865
|
-
if (propType.type === "boolean") {
|
|
1866
|
-
return ["true", "false"];
|
|
1867
|
-
}
|
|
1868
|
-
if (propType.type === "property") {
|
|
1869
|
-
return this.utility.getPropertyKeys(propType.value || property);
|
|
1870
|
-
}
|
|
1871
|
-
if (propType.type === "token") {
|
|
1872
|
-
const values = this.tokens.view.getCategoryValues(propType.value);
|
|
1873
|
-
return Object.keys(values ?? {});
|
|
1874
|
-
}
|
|
1875
|
-
};
|
|
1876
|
-
getPropertyType = (prop) => {
|
|
1877
|
-
switch (prop.type) {
|
|
1878
|
-
case "enum":
|
|
1879
|
-
return `ConditionalValue<${(0, import_shared12.unionType)(prop.value)}>`;
|
|
1880
|
-
case "token": {
|
|
1881
|
-
const tokenType = `Tokens["${prop.value}"]`;
|
|
1882
|
-
if (prop.property) {
|
|
1883
|
-
return `ConditionalValue<${tokenType} | Properties["${prop.property}"]>`;
|
|
1884
|
-
}
|
|
1885
|
-
return `ConditionalValue<${tokenType}>`;
|
|
1886
|
-
}
|
|
1887
|
-
case "property":
|
|
1888
|
-
return `SystemProperties["${prop.value}"]`;
|
|
1889
|
-
case "string":
|
|
1890
|
-
case "number":
|
|
1891
|
-
case "boolean":
|
|
1892
|
-
return `ConditionalValue<${prop.type}>`;
|
|
1893
|
-
default:
|
|
1894
|
-
return `ConditionalValue<${prop.type || "unknown"}>`;
|
|
1895
|
-
}
|
|
1896
|
-
};
|
|
1897
|
-
static isValidNode = (node) => {
|
|
1898
|
-
return (0, import_shared12.isObject)(node) && "type" in node && node.type === "recipe";
|
|
1899
|
-
};
|
|
1900
|
-
};
|
|
1901
|
-
|
|
1902
|
-
// src/recipes.ts
|
|
1903
|
-
var import_shared14 = require("@bamboocss/shared");
|
|
1904
|
-
var import_lodash2 = __toESM(require("lodash.merge"));
|
|
1905
|
-
|
|
1906
|
-
// src/serialize.ts
|
|
1907
|
-
var import_shared13 = require("@bamboocss/shared");
|
|
1908
|
-
var import_lodash = __toESM(require("lodash.merge"));
|
|
1909
|
-
function transformStyles(context, styleObj, key) {
|
|
1910
|
-
const encoder = context.encoder.clone();
|
|
1911
|
-
const decoder = context.decoder.clone();
|
|
1912
|
-
const hashSet = /* @__PURE__ */ new Set();
|
|
1913
|
-
encoder.hashStyleObject(hashSet, styleObj);
|
|
1914
|
-
const group = decoder.getGroup(hashSet, key);
|
|
1915
|
-
return group.result;
|
|
1916
|
-
}
|
|
1917
|
-
function serializeStyles(context, groupedObject) {
|
|
1918
|
-
const result = {};
|
|
1919
|
-
for (const [scope, styles] of Object.entries(groupedObject)) {
|
|
1920
|
-
result[scope] ||= {};
|
|
1921
|
-
const styleObject = (0, import_shared13.walkObject)(styles, (value) => value, {
|
|
1922
|
-
getKey: (prop, value) => {
|
|
1923
|
-
if ((0, import_shared13.isObject)(value) && !context.conditions.isCondition(prop) && !context.isValidProperty(prop)) {
|
|
1924
|
-
const selectors = parseSelectors(prop);
|
|
1925
|
-
return selectors.map((s) => "& " + s).join(", ");
|
|
1926
|
-
}
|
|
1927
|
-
return prop;
|
|
1928
|
-
}
|
|
1929
|
-
});
|
|
1930
|
-
(0, import_lodash.default)(result[scope], transformStyles(context, styleObject, scope));
|
|
1931
|
-
}
|
|
1932
|
-
return result;
|
|
1933
|
-
}
|
|
1934
|
-
|
|
1935
|
-
// src/recipes.ts
|
|
1936
|
-
var sharedState = {
|
|
1937
|
-
/**
|
|
1938
|
-
* The map of recipe names to their resolved class names
|
|
1939
|
-
*/
|
|
1940
|
-
classNames: /* @__PURE__ */ new Map(),
|
|
1941
|
-
/**
|
|
1942
|
-
* The map of the property to their resolved styles
|
|
1943
|
-
*/
|
|
1944
|
-
styles: /* @__PURE__ */ new Map(),
|
|
1945
|
-
/**
|
|
1946
|
-
* The map of the recipes with their resolved styles
|
|
1947
|
-
*/
|
|
1948
|
-
nodes: /* @__PURE__ */ new Map(),
|
|
1949
|
-
/**
|
|
1950
|
-
* The map of recipe key to slot key + slot recipe
|
|
1951
|
-
*/
|
|
1952
|
-
slots: /* @__PURE__ */ new Map()
|
|
1953
|
-
};
|
|
1954
|
-
var Recipes = class _Recipes {
|
|
1955
|
-
constructor(recipes = {}) {
|
|
1956
|
-
this.recipes = recipes;
|
|
1957
|
-
this.prune();
|
|
1958
|
-
}
|
|
1959
|
-
slotSeparator = "__";
|
|
1960
|
-
keys = [];
|
|
1961
|
-
deprecated = /* @__PURE__ */ new Set();
|
|
1962
|
-
context;
|
|
1963
|
-
get config() {
|
|
1964
|
-
return this.recipes;
|
|
1965
|
-
}
|
|
1966
|
-
getPropKey = (recipe, variant, value) => {
|
|
1967
|
-
return `${recipe} (${variant} = ${value})`;
|
|
1968
|
-
};
|
|
1969
|
-
get separator() {
|
|
1970
|
-
return this.context.utility.separator ?? "_";
|
|
1971
|
-
}
|
|
1972
|
-
getClassName = (className, variant, value) => {
|
|
1973
|
-
return `${className}--${variant}${this.separator}${value}`;
|
|
1974
|
-
};
|
|
1975
|
-
// check this.recipes against sharedState.nodes
|
|
1976
|
-
// and remove any recipes (in sharedState) that are no longer in use
|
|
1977
|
-
prune = () => {
|
|
1978
|
-
const recipeNames = Object.keys(this.recipes);
|
|
1979
|
-
const cachedRecipeNames = Array.from(sharedState.nodes.keys());
|
|
1980
|
-
const removedRecipes = cachedRecipeNames.filter((name) => !recipeNames.includes(name));
|
|
1981
|
-
removedRecipes.forEach((name) => {
|
|
1982
|
-
this.remove(name);
|
|
1983
|
-
});
|
|
1984
|
-
};
|
|
1985
|
-
save = (context) => {
|
|
1986
|
-
this.context = context;
|
|
1987
|
-
for (const [name, recipe] of Object.entries(this.recipes)) {
|
|
1988
|
-
this.saveOne(name, recipe);
|
|
1989
|
-
}
|
|
1990
|
-
this.keys = Object.keys(this.recipes);
|
|
1991
|
-
};
|
|
1992
|
-
saveOne = (name, recipe) => {
|
|
1993
|
-
if (_Recipes.isSlotRecipeConfig(recipe)) {
|
|
1994
|
-
const slots = (0, import_shared14.getSlotRecipes)(recipe);
|
|
1995
|
-
const slotsMap = /* @__PURE__ */ new Map();
|
|
1996
|
-
Object.entries(slots).forEach(([slot, slotRecipe]) => {
|
|
1997
|
-
const slotName = this.getSlotKey(name, slot);
|
|
1998
|
-
this.normalize(slotName, slotRecipe);
|
|
1999
|
-
slotsMap.set(slotName, slotRecipe);
|
|
2000
|
-
});
|
|
2001
|
-
this.assignRecipe(name, recipe);
|
|
2002
|
-
sharedState.slots.set(name, slotsMap);
|
|
2003
|
-
} else {
|
|
2004
|
-
this.assignRecipe(name, this.normalize(name, recipe));
|
|
2005
|
-
}
|
|
2006
|
-
};
|
|
2007
|
-
remove(name) {
|
|
2008
|
-
sharedState.nodes.delete(name);
|
|
2009
|
-
sharedState.classNames.delete(name);
|
|
2010
|
-
sharedState.styles.delete(name);
|
|
2011
|
-
}
|
|
2012
|
-
inferJsxSlots = (name, recipe) => {
|
|
2013
|
-
const capitalized = (0, import_shared14.capitalize)(name);
|
|
2014
|
-
const jsx = Array.from(recipe.jsx ?? [capitalized]);
|
|
2015
|
-
const ROOT_SLOT = "root";
|
|
2016
|
-
if (_Recipes.isSlotRecipeConfig(recipe)) {
|
|
2017
|
-
const jsxRootName = (0, import_shared14.capitalize)(ROOT_SLOT);
|
|
2018
|
-
const rootNames = [`${capitalized}.${jsxRootName}`, `${capitalized}${jsxRootName}`];
|
|
2019
|
-
jsx.push(...rootNames);
|
|
2020
|
-
}
|
|
2021
|
-
return jsx;
|
|
2022
|
-
};
|
|
2023
|
-
assignRecipe = (name, recipe) => {
|
|
2024
|
-
if (recipe.deprecated) this.deprecated.add(name);
|
|
2025
|
-
const variantKeys = Object.keys(recipe.variants ?? {});
|
|
2026
|
-
const jsx = this.inferJsxSlots(name, recipe);
|
|
2027
|
-
sharedState.nodes.set(name, {
|
|
2028
|
-
...this.getNames(name),
|
|
2029
|
-
className: recipe.className ?? name,
|
|
2030
|
-
jsx,
|
|
2031
|
-
type: "recipe",
|
|
2032
|
-
variantKeys,
|
|
2033
|
-
variantKeyMap: Object.fromEntries(
|
|
2034
|
-
Object.entries(recipe.variants ?? {}).map(([key, value]) => {
|
|
2035
|
-
return [key, Object.keys(value)];
|
|
2036
|
-
})
|
|
2037
|
-
),
|
|
2038
|
-
match: (0, import_shared14.createRegex)(jsx),
|
|
2039
|
-
config: recipe,
|
|
2040
|
-
splitProps: (props) => {
|
|
2041
|
-
return (0, import_shared14.splitProps)(props, variantKeys);
|
|
2042
|
-
},
|
|
2043
|
-
props: variantKeys
|
|
2044
|
-
});
|
|
2045
|
-
};
|
|
2046
|
-
getSlotKey = (name, slot) => {
|
|
2047
|
-
return `${name}${this.slotSeparator}${slot}`;
|
|
2048
|
-
};
|
|
2049
|
-
isEmpty = () => {
|
|
2050
|
-
return sharedState.nodes.size === 0;
|
|
2051
|
-
};
|
|
2052
|
-
isDeprecated = (name) => {
|
|
2053
|
-
return this.deprecated.has(name);
|
|
2054
|
-
};
|
|
2055
|
-
getNames = (0, import_shared14.memo)((name) => {
|
|
2056
|
-
return {
|
|
2057
|
-
baseName: name,
|
|
2058
|
-
upperName: (0, import_shared14.capitalize)(name),
|
|
2059
|
-
dashName: (0, import_shared14.dashCase)(name),
|
|
2060
|
-
jsxName: (0, import_shared14.capitalize)(name)
|
|
2061
|
-
};
|
|
2062
|
-
});
|
|
2063
|
-
getRecipe = (0, import_shared14.memo)((name) => {
|
|
2064
|
-
return sharedState.nodes.get(name);
|
|
2065
|
-
});
|
|
2066
|
-
getConfig = (0, import_shared14.memo)((name) => {
|
|
2067
|
-
return this.recipes[name];
|
|
2068
|
-
});
|
|
2069
|
-
getConfigOrThrow = (0, import_shared14.memo)((name) => {
|
|
2070
|
-
const config = this.getConfig(name);
|
|
2071
|
-
if (!config) throw new import_shared14.BambooError("UNKNOWN_RECIPE", `Recipe "${name}" not found`);
|
|
2072
|
-
return config;
|
|
2073
|
-
});
|
|
2074
|
-
find = (0, import_shared14.memo)((jsxName) => {
|
|
2075
|
-
return this.details.find((node) => node.match.test(jsxName));
|
|
2076
|
-
});
|
|
2077
|
-
filter = (0, import_shared14.memo)((jsxName) => {
|
|
2078
|
-
return this.details.filter((node) => node.match.test(jsxName));
|
|
2079
|
-
});
|
|
2080
|
-
get details() {
|
|
2081
|
-
return Array.from(sharedState.nodes.values());
|
|
2082
|
-
}
|
|
2083
|
-
splitProps = (recipeName, props) => {
|
|
2084
|
-
const recipe = this.details.find((node) => node.baseName === recipeName);
|
|
2085
|
-
if (!recipe) return [{}, props];
|
|
2086
|
-
return recipe.splitProps(props);
|
|
2087
|
-
};
|
|
2088
|
-
isSlotRecipe = (name) => {
|
|
2089
|
-
return sharedState.slots.has(name);
|
|
2090
|
-
};
|
|
2091
|
-
static isSlotRecipeConfig = (config) => {
|
|
2092
|
-
return "slots" in config && Array.isArray(config.slots) && config.slots.length > 0;
|
|
2093
|
-
};
|
|
2094
|
-
normalize = (name, config) => {
|
|
2095
|
-
const {
|
|
2096
|
-
jsx = [(0, import_shared14.capitalize)(name)],
|
|
2097
|
-
base = {},
|
|
2098
|
-
variants = {},
|
|
2099
|
-
defaultVariants = {},
|
|
2100
|
-
description = "",
|
|
2101
|
-
compoundVariants = [],
|
|
2102
|
-
staticCss = []
|
|
2103
|
-
} = config;
|
|
2104
|
-
const className = config.className ?? name;
|
|
2105
|
-
const recipe = {
|
|
2106
|
-
...config,
|
|
2107
|
-
deprecated: config.deprecated == null ? false : config.deprecated,
|
|
2108
|
-
jsx,
|
|
2109
|
-
className,
|
|
2110
|
-
description,
|
|
2111
|
-
base: {},
|
|
2112
|
-
variants: {},
|
|
2113
|
-
defaultVariants,
|
|
2114
|
-
compoundVariants,
|
|
2115
|
-
staticCss
|
|
2116
|
-
};
|
|
2117
|
-
recipe.base = transformStyles(this.context, base, name);
|
|
2118
|
-
sharedState.styles.set(name, recipe.base);
|
|
2119
|
-
sharedState.classNames.set(name, recipe.className);
|
|
2120
|
-
for (const [key, variant] of Object.entries(variants)) {
|
|
2121
|
-
for (const [variantKey, styles] of Object.entries(variant)) {
|
|
2122
|
-
const propKey = this.getPropKey(name, key, variantKey);
|
|
2123
|
-
const className2 = this.getClassName(recipe.className, key, variantKey);
|
|
2124
|
-
const styleObject = transformStyles(this.context, styles, className2);
|
|
2125
|
-
sharedState.styles.set(propKey, styleObject);
|
|
2126
|
-
sharedState.classNames.set(propKey, className2);
|
|
2127
|
-
(0, import_lodash2.default)(recipe.variants, {
|
|
2128
|
-
[key]: { [variantKey]: styleObject }
|
|
2129
|
-
});
|
|
2130
|
-
}
|
|
2131
|
-
}
|
|
2132
|
-
return recipe;
|
|
2133
|
-
};
|
|
2134
|
-
getTransform = (name, slot) => {
|
|
2135
|
-
return (variant, value) => {
|
|
2136
|
-
if (value === "__ignore__") {
|
|
2137
|
-
return {
|
|
2138
|
-
layer: slot ? "recipes_slots_base" : "recipes_base",
|
|
2139
|
-
className: sharedState.classNames.get(name),
|
|
2140
|
-
styles: sharedState.styles.get(name) ?? {}
|
|
2141
|
-
};
|
|
2142
|
-
}
|
|
2143
|
-
const propKey = this.getPropKey(name, variant, value);
|
|
2144
|
-
return {
|
|
2145
|
-
className: sharedState.classNames.get(propKey),
|
|
2146
|
-
styles: sharedState.styles.get(propKey) ?? {}
|
|
2147
|
-
};
|
|
2148
|
-
};
|
|
2149
|
-
};
|
|
2150
|
-
filterDetails = (filters) => {
|
|
2151
|
-
const recipeDiffs = filters?.affecteds?.recipes;
|
|
2152
|
-
return recipeDiffs ? this.details.filter((recipe) => recipeDiffs.includes(recipe.dashName)) : this.details;
|
|
2153
|
-
};
|
|
2154
|
-
static inferSlots = (recipe) => {
|
|
2155
|
-
const slots = /* @__PURE__ */ new Set();
|
|
2156
|
-
Object.keys(recipe.base ?? {}).forEach((name) => {
|
|
2157
|
-
slots.add(name);
|
|
2158
|
-
});
|
|
2159
|
-
Object.values(recipe.variants ?? {}).forEach((variants) => {
|
|
2160
|
-
Object.keys(variants).forEach((name) => {
|
|
2161
|
-
slots.add(name);
|
|
2162
|
-
});
|
|
2163
|
-
});
|
|
2164
|
-
recipe.compoundVariants?.forEach((compoundVariant) => {
|
|
2165
|
-
if (!compoundVariant) return;
|
|
2166
|
-
Object.keys(compoundVariant.css ?? {}).forEach((name) => {
|
|
2167
|
-
slots.add(name);
|
|
2168
|
-
});
|
|
2169
|
-
});
|
|
2170
|
-
return Array.from(slots);
|
|
2171
|
-
};
|
|
2172
|
-
static isValidNode = (node) => {
|
|
2173
|
-
return (0, import_shared14.isObject)(node) && "type" in node && node.type === "recipe";
|
|
2174
|
-
};
|
|
2175
|
-
};
|
|
2176
|
-
|
|
2177
|
-
// src/static-css.ts
|
|
2178
|
-
var import_logger3 = require("@bamboocss/logger");
|
|
2179
|
-
var import_shared17 = require("@bamboocss/shared");
|
|
2180
|
-
|
|
2181
|
-
// src/style-decoder.ts
|
|
2182
|
-
var import_shared16 = require("@bamboocss/shared");
|
|
2183
|
-
|
|
2184
|
-
// src/style-encoder.ts
|
|
2185
|
-
var import_shared15 = require("@bamboocss/shared");
|
|
2186
|
-
|
|
2187
|
-
// package.json
|
|
2188
|
-
var version = "1.11.1";
|
|
2189
|
-
|
|
2190
|
-
// src/style-encoder.ts
|
|
2191
|
-
var urlRegex = /^https?:\/\//;
|
|
2192
|
-
var StyleEncoder = class _StyleEncoder {
|
|
2193
|
-
constructor(context) {
|
|
2194
|
-
this.context = context;
|
|
2195
|
-
}
|
|
2196
|
-
static separator = "]___[";
|
|
2197
|
-
static conditionSeparator = "<___>";
|
|
2198
|
-
atomic = /* @__PURE__ */ new Set();
|
|
2199
|
-
compound_variants = /* @__PURE__ */ new Set();
|
|
2200
|
-
//
|
|
2201
|
-
recipes = /* @__PURE__ */ new Map();
|
|
2202
|
-
recipes_base = /* @__PURE__ */ new Map();
|
|
2203
|
-
grouped = /* @__PURE__ */ new Map();
|
|
2204
|
-
filterStyleProps = (props) => {
|
|
2205
|
-
if (this.context.isTemplateLiteralSyntax) return props;
|
|
2206
|
-
return filterProps(this.context.isValidProperty, props);
|
|
2207
|
-
};
|
|
2208
|
-
clone = () => {
|
|
2209
|
-
return new _StyleEncoder(this.context);
|
|
2210
|
-
};
|
|
2211
|
-
isEmpty = () => {
|
|
2212
|
-
return !this.atomic.size && !this.recipes.size && !this.compound_variants.size && !this.recipes_base.size && !this.grouped.size;
|
|
2213
|
-
};
|
|
2214
|
-
get results() {
|
|
2215
|
-
return {
|
|
2216
|
-
atomic: this.atomic,
|
|
2217
|
-
recipes: this.recipes,
|
|
2218
|
-
recipes_base: this.recipes_base,
|
|
2219
|
-
grouped: this.grouped
|
|
2220
|
-
};
|
|
2221
|
-
}
|
|
2222
|
-
/**
|
|
2223
|
-
* Hashes a style object and adds the resulting hashes to a set.
|
|
2224
|
-
* @param set - The set to add the resulting hashes to.
|
|
2225
|
-
* @param obj - The style object to hash.
|
|
2226
|
-
* @param baseEntry - An optional base style entry to use when hashing the style object.
|
|
2227
|
-
*/
|
|
2228
|
-
hashStyleObject = (set, obj, baseEntry) => {
|
|
2229
|
-
const isCondition = this.context.conditions.isCondition;
|
|
2230
|
-
const traverseOptions = { separator: _StyleEncoder.conditionSeparator };
|
|
2231
|
-
let prop = "";
|
|
2232
|
-
let prevProp = "";
|
|
2233
|
-
const isRecipe = !!baseEntry?.variants;
|
|
2234
|
-
const normalized = (0, import_shared15.normalizeStyleObject)(obj, this.context, !isRecipe);
|
|
2235
|
-
(0, import_shared15.traverse)(
|
|
2236
|
-
normalized,
|
|
2237
|
-
({ key, value: rawValue, path }) => {
|
|
2238
|
-
if (rawValue === void 0) {
|
|
2239
|
-
return;
|
|
2240
|
-
}
|
|
2241
|
-
if (urlRegex.test(rawValue)) {
|
|
2242
|
-
return;
|
|
2243
|
-
}
|
|
2244
|
-
const value = Array.isArray(rawValue) ? (0, import_shared15.toResponsiveObject)(rawValue, this.context.conditions.breakpoints.keys) : rawValue;
|
|
2245
|
-
prop = key;
|
|
2246
|
-
if (isCondition(key)) {
|
|
2247
|
-
if ((0, import_shared15.isObjectOrArray)(value)) {
|
|
2248
|
-
return;
|
|
2249
|
-
}
|
|
2250
|
-
prop = prevProp;
|
|
2251
|
-
} else if ((0, import_shared15.isObjectOrArray)(value)) {
|
|
2252
|
-
prevProp = prop;
|
|
2253
|
-
return;
|
|
2254
|
-
}
|
|
2255
|
-
const resolvedCondition = getResolvedCondition(path, isCondition);
|
|
2256
|
-
const hashed = hashStyleEntry(Object.assign(baseEntry ?? {}, { prop, value, cond: resolvedCondition }));
|
|
2257
|
-
set.add(hashed);
|
|
2258
|
-
prevProp = prop;
|
|
2259
|
-
},
|
|
2260
|
-
traverseOptions
|
|
2261
|
-
);
|
|
2262
|
-
};
|
|
2263
|
-
processAtomic = (styles) => {
|
|
2264
|
-
this.hashStyleObject(this.atomic, styles);
|
|
2265
|
-
};
|
|
2266
|
-
processGrouped = (styles) => {
|
|
2267
|
-
const groupSet = /* @__PURE__ */ new Set();
|
|
2268
|
-
this.hashStyleObject(groupSet, styles);
|
|
2269
|
-
if (groupSet.size === 0) return;
|
|
2270
|
-
const sortedHashes = Array.from(groupSet).sort();
|
|
2271
|
-
const groupId = sortedHashes.join("|");
|
|
2272
|
-
const existing = this.grouped.get(groupId);
|
|
2273
|
-
if (existing) return;
|
|
2274
|
-
this.grouped.set(groupId, groupSet);
|
|
2275
|
-
};
|
|
2276
|
-
processStyleProps = (styleProps, grouped = false) => {
|
|
2277
|
-
const processFn = grouped ? this.processGrouped : this.processAtomic;
|
|
2278
|
-
const styles = this.filterStyleProps(styleProps);
|
|
2279
|
-
const rest = {};
|
|
2280
|
-
for (const [key, value] of Object.entries(styles)) {
|
|
2281
|
-
if (key === "css" || key.endsWith("Css")) {
|
|
2282
|
-
if (Array.isArray(value)) {
|
|
2283
|
-
value.forEach((style) => processFn(style));
|
|
2284
|
-
} else if (value) {
|
|
2285
|
-
processFn(value);
|
|
2286
|
-
}
|
|
2287
|
-
} else {
|
|
2288
|
-
rest[key] = value;
|
|
2289
|
-
}
|
|
2290
|
-
}
|
|
2291
|
-
processFn(rest);
|
|
2292
|
-
};
|
|
2293
|
-
processConfigSlotRecipeBase = (recipeName, config) => {
|
|
2294
|
-
config.slots.forEach((slot) => {
|
|
2295
|
-
const recipeKey = this.context.recipes.getSlotKey(recipeName, slot);
|
|
2296
|
-
const slotBase = config.base?.[slot];
|
|
2297
|
-
if (!slotBase || this.recipes_base.has(recipeKey)) return;
|
|
2298
|
-
const base_set = (0, import_shared15.getOrCreateSet)(this.recipes_base, recipeKey);
|
|
2299
|
-
this.hashStyleObject(base_set, slotBase, { recipe: recipeName, slot });
|
|
2300
|
-
});
|
|
2301
|
-
};
|
|
2302
|
-
processConfigSlotRecipe = (recipeName, variants) => {
|
|
2303
|
-
const config = this.context.recipes.getConfig(recipeName);
|
|
2304
|
-
if (!Recipes.isSlotRecipeConfig(config)) return;
|
|
2305
|
-
this.processConfigSlotRecipeBase(recipeName, config);
|
|
2306
|
-
const set = (0, import_shared15.getOrCreateSet)(this.recipes, recipeName);
|
|
2307
|
-
const computedVariants = Object.assign({}, config.defaultVariants, variants);
|
|
2308
|
-
this.hashStyleObject(set, computedVariants, { recipe: recipeName, variants: true });
|
|
2309
|
-
if (!config.compoundVariants || this.compound_variants.has(recipeName)) return;
|
|
2310
|
-
this.compound_variants.add(recipeName);
|
|
2311
|
-
config.compoundVariants.forEach((compoundVariant) => {
|
|
2312
|
-
if (!compoundVariant) return;
|
|
2313
|
-
Object.values(compoundVariant.css).forEach((values) => {
|
|
2314
|
-
if (!values) return;
|
|
2315
|
-
this.processAtomic(values);
|
|
2316
|
-
});
|
|
2317
|
-
});
|
|
2318
|
-
};
|
|
2319
|
-
processConfigRecipeBase = (recipeName, config) => {
|
|
2320
|
-
if (!config.base || this.recipes_base.has(recipeName)) return;
|
|
2321
|
-
const base_set = (0, import_shared15.getOrCreateSet)(this.recipes_base, recipeName);
|
|
2322
|
-
this.hashStyleObject(base_set, config.base, { recipe: recipeName });
|
|
2323
|
-
};
|
|
2324
|
-
processConfigRecipe = (recipeName, variants) => {
|
|
2325
|
-
const config = this.context.recipes.getConfig(recipeName);
|
|
2326
|
-
if (!config) return;
|
|
2327
|
-
this.processConfigRecipeBase(recipeName, config);
|
|
2328
|
-
const set = (0, import_shared15.getOrCreateSet)(this.recipes, recipeName);
|
|
2329
|
-
const computedVariants = Object.assign({}, config.defaultVariants, variants);
|
|
2330
|
-
this.hashStyleObject(set, computedVariants, { recipe: recipeName, variants: true });
|
|
2331
|
-
if (!config.compoundVariants || this.compound_variants.has(recipeName)) return;
|
|
2332
|
-
this.compound_variants.add(recipeName);
|
|
2333
|
-
config.compoundVariants.forEach((compoundVariant) => {
|
|
2334
|
-
if (!compoundVariant) return;
|
|
2335
|
-
this.processAtomic(compoundVariant.css);
|
|
2336
|
-
});
|
|
2337
|
-
};
|
|
2338
|
-
processRecipe = (recipeName, variants) => {
|
|
2339
|
-
if (this.context.recipes.isSlotRecipe(recipeName)) {
|
|
2340
|
-
this.processConfigSlotRecipe(recipeName, variants);
|
|
2341
|
-
} else {
|
|
2342
|
-
this.processConfigRecipe(recipeName, variants);
|
|
2343
|
-
}
|
|
2344
|
-
};
|
|
2345
|
-
processRecipeBase(recipeName) {
|
|
2346
|
-
const config = this.context.recipes.getConfig(recipeName);
|
|
2347
|
-
if (!config) return;
|
|
2348
|
-
if (this.context.recipes.isSlotRecipe(recipeName)) {
|
|
2349
|
-
this.processConfigSlotRecipeBase(recipeName, config);
|
|
2350
|
-
} else {
|
|
2351
|
-
this.processConfigRecipeBase(recipeName, config);
|
|
2352
|
-
}
|
|
2353
|
-
}
|
|
2354
|
-
processPattern = (name, patternProps, type, jsxName) => {
|
|
2355
|
-
let fnName = name;
|
|
2356
|
-
if (type === "jsx-pattern" && jsxName) {
|
|
2357
|
-
fnName = this.context.patterns.find(jsxName);
|
|
2358
|
-
}
|
|
2359
|
-
const styleProps = this.context.patterns.transform(fnName, patternProps);
|
|
2360
|
-
this.processStyleProps(styleProps);
|
|
2361
|
-
};
|
|
2362
|
-
processAtomicRecipe = (recipe) => {
|
|
2363
|
-
const { base = {}, variants = {}, compoundVariants = [] } = recipe;
|
|
2364
|
-
this.processAtomic(base);
|
|
2365
|
-
for (const variant of Object.values(variants)) {
|
|
2366
|
-
for (const styles of Object.values(variant)) {
|
|
2367
|
-
this.processAtomic(styles);
|
|
2368
|
-
}
|
|
2369
|
-
}
|
|
2370
|
-
compoundVariants.forEach((compoundVariant) => {
|
|
2371
|
-
if (!compoundVariant) return;
|
|
2372
|
-
this.processAtomic(compoundVariant.css);
|
|
2373
|
-
});
|
|
2374
|
-
};
|
|
2375
|
-
processAtomicSlotRecipe = (recipe) => {
|
|
2376
|
-
const inferredSlots = Recipes.inferSlots(recipe);
|
|
2377
|
-
recipe.slots = (0, import_shared15.uniq)([...recipe.slots ?? [], ...inferredSlots].filter(Boolean));
|
|
2378
|
-
const slots = (0, import_shared15.getSlotRecipes)(recipe);
|
|
2379
|
-
for (const slotRecipe of Object.values(slots)) {
|
|
2380
|
-
this.processAtomicRecipe(slotRecipe);
|
|
2381
|
-
}
|
|
2382
|
-
};
|
|
2383
|
-
getConfigRecipeHash = (recipeName) => {
|
|
2384
|
-
return {
|
|
2385
|
-
atomic: this.atomic,
|
|
2386
|
-
base: this.recipes_base.get(recipeName),
|
|
2387
|
-
variants: this.recipes.get(recipeName)
|
|
2388
|
-
};
|
|
2389
|
-
};
|
|
2390
|
-
getConfigSlotRecipeHash = (recipeName) => {
|
|
2391
|
-
const recipeConfig = this.context.recipes.getConfigOrThrow(recipeName);
|
|
2392
|
-
if (!Recipes.isSlotRecipeConfig(recipeConfig)) {
|
|
2393
|
-
throw new import_shared15.BambooError("INVALID_RECIPE", `Recipe "${recipeName}" is not a slot recipe`);
|
|
2394
|
-
}
|
|
2395
|
-
const base = {};
|
|
2396
|
-
recipeConfig.slots.map((slot) => {
|
|
2397
|
-
const recipeKey = this.context.recipes.getSlotKey(recipeName, slot);
|
|
2398
|
-
base[slot] = this.recipes_base.get(recipeKey);
|
|
2399
|
-
});
|
|
2400
|
-
return {
|
|
2401
|
-
atomic: this.atomic,
|
|
2402
|
-
base,
|
|
2403
|
-
variants: this.recipes.get(recipeName)
|
|
2404
|
-
};
|
|
2405
|
-
};
|
|
2406
|
-
getRecipeHash = (recipeName) => {
|
|
2407
|
-
if (this.context.recipes.isSlotRecipe(recipeName)) {
|
|
2408
|
-
return this.getConfigSlotRecipeHash(recipeName);
|
|
2409
|
-
}
|
|
2410
|
-
return this.getConfigRecipeHash(recipeName);
|
|
2411
|
-
};
|
|
2412
|
-
toJSON = () => {
|
|
2413
|
-
const styles = {
|
|
2414
|
-
atomic: Array.from(this.atomic),
|
|
2415
|
-
recipes: Object.fromEntries(Array.from(this.recipes.entries()).map(([name, set]) => [name, Array.from(set)]))
|
|
2416
|
-
};
|
|
2417
|
-
if (this.grouped.size) {
|
|
2418
|
-
styles.grouped = Object.fromEntries(Array.from(this.grouped.entries()).map(([id, set]) => [id, Array.from(set)]));
|
|
2419
|
-
}
|
|
2420
|
-
return {
|
|
2421
|
-
schemaVersion: version,
|
|
2422
|
-
styles
|
|
2423
|
-
};
|
|
2424
|
-
};
|
|
2425
|
-
fromJSON = (json) => {
|
|
2426
|
-
const { styles } = json;
|
|
2427
|
-
styles.atomic?.forEach((hash) => this.atomic.add(hash));
|
|
2428
|
-
Object.entries(styles.recipes ?? {}).forEach(([recipeName, hashes]) => {
|
|
2429
|
-
this.processRecipeBase(recipeName);
|
|
2430
|
-
const set = (0, import_shared15.getOrCreateSet)(this.recipes, recipeName);
|
|
2431
|
-
hashes.forEach((hash) => set.add(hash));
|
|
2432
|
-
});
|
|
2433
|
-
Object.entries(styles.grouped ?? {}).forEach(([groupId, hashes]) => {
|
|
2434
|
-
const set = (0, import_shared15.getOrCreateSet)(this.grouped, groupId);
|
|
2435
|
-
hashes.forEach((hash) => set.add(hash));
|
|
2436
|
-
});
|
|
2437
|
-
return this;
|
|
2438
|
-
};
|
|
2439
|
-
};
|
|
2440
|
-
var filterProps = (isValidProperty, props) => {
|
|
2441
|
-
const clone = {};
|
|
2442
|
-
for (const [key, value] of Object.entries(props)) {
|
|
2443
|
-
if ((isValidProperty(key) || key === "css" || key.endsWith("Css")) && value !== void 0) {
|
|
2444
|
-
clone[key] = value;
|
|
2445
|
-
}
|
|
2446
|
-
}
|
|
2447
|
-
return clone;
|
|
2448
|
-
};
|
|
2449
|
-
var hashStyleEntry = (entry) => {
|
|
2450
|
-
const parts = [`${entry.prop}${StyleEncoder.separator}value:${entry.value}`];
|
|
2451
|
-
if (entry.cond) {
|
|
2452
|
-
parts.push(`cond:${entry.cond}`);
|
|
2453
|
-
}
|
|
2454
|
-
if (entry.recipe) {
|
|
2455
|
-
parts.push(`recipe:${entry.recipe}`);
|
|
2456
|
-
}
|
|
2457
|
-
if (entry.layer) {
|
|
2458
|
-
parts.push(`layer:${entry.layer}`);
|
|
2459
|
-
}
|
|
2460
|
-
if (entry.slot) {
|
|
2461
|
-
parts.push(`slot:${entry.slot}`);
|
|
2462
|
-
}
|
|
2463
|
-
return parts.join(StyleEncoder.separator);
|
|
2464
|
-
};
|
|
2465
|
-
var getResolvedCondition = (cond, isCondition) => {
|
|
2466
|
-
if (!cond) {
|
|
2467
|
-
return "";
|
|
2468
|
-
}
|
|
2469
|
-
const parts = cond.split(StyleEncoder.conditionSeparator);
|
|
2470
|
-
const relevantParts = parts.filter((part) => part !== "base" && isCondition(part));
|
|
2471
|
-
if (parts.length !== relevantParts.length) {
|
|
2472
|
-
return relevantParts.join(StyleEncoder.conditionSeparator);
|
|
2473
|
-
}
|
|
2474
|
-
return cond;
|
|
2475
|
-
};
|
|
2476
|
-
|
|
2477
|
-
// src/style-decoder.ts
|
|
2478
|
-
var StyleDecoder = class _StyleDecoder {
|
|
2479
|
-
constructor(context) {
|
|
2480
|
-
this.context = context;
|
|
2481
|
-
}
|
|
2482
|
-
classNames = /* @__PURE__ */ new Map();
|
|
2483
|
-
//
|
|
2484
|
-
atomic_cache = /* @__PURE__ */ new Map();
|
|
2485
|
-
group_cache = /* @__PURE__ */ new Map();
|
|
2486
|
-
recipe_base_cache = /* @__PURE__ */ new Map();
|
|
2487
|
-
//
|
|
2488
|
-
atomic = /* @__PURE__ */ new Set();
|
|
2489
|
-
grouped = /* @__PURE__ */ new Set();
|
|
2490
|
-
//
|
|
2491
|
-
recipes = /* @__PURE__ */ new Map();
|
|
2492
|
-
recipes_base = /* @__PURE__ */ new Map();
|
|
2493
|
-
clone = () => {
|
|
2494
|
-
return new _StyleDecoder(this.context);
|
|
2495
|
-
};
|
|
2496
|
-
isEmpty = () => {
|
|
2497
|
-
return !this.atomic.size && !this.grouped.size && !this.recipes.size && !this.recipes_base.size;
|
|
2498
|
-
};
|
|
2499
|
-
get results() {
|
|
2500
|
-
return {
|
|
2501
|
-
atomic: this.atomic,
|
|
2502
|
-
grouped: this.grouped,
|
|
2503
|
-
recipes: this.recipes,
|
|
2504
|
-
recipes_base: this.recipes_base
|
|
2505
|
-
};
|
|
2506
|
-
}
|
|
2507
|
-
formatSelector = (conditions, className) => {
|
|
2508
|
-
const { conditions: cond, hash, utility } = this.context;
|
|
2509
|
-
const conds = cond.finalize(conditions);
|
|
2510
|
-
let result;
|
|
2511
|
-
if (hash.className) {
|
|
2512
|
-
conds.push(className);
|
|
2513
|
-
result = utility.formatClassName(utility.toHash(conds, utility.defaultHashFn));
|
|
2514
|
-
} else {
|
|
2515
|
-
conds.push(utility.formatClassName(className));
|
|
2516
|
-
result = conds.join(":");
|
|
2517
|
-
}
|
|
2518
|
-
return (0, import_shared16.esc)(result);
|
|
2519
|
-
};
|
|
2520
|
-
getRecipeName = (hash) => {
|
|
2521
|
-
const entry = getEntryFromHash(hash);
|
|
2522
|
-
if (!entry.recipe) return;
|
|
2523
|
-
return entry.slot ? this.context.recipes.getSlotKey(entry.recipe, entry.slot) : entry.recipe;
|
|
2524
|
-
};
|
|
2525
|
-
getTransformResult = (hash) => {
|
|
2526
|
-
const entry = getEntryFromHash(hash);
|
|
2527
|
-
const recipeName = this.getRecipeName(hash);
|
|
2528
|
-
const transform = recipeName ? this.context.recipes.getTransform(recipeName) : this.context.utility.transform;
|
|
2529
|
-
const transformed = transform(entry.prop, (0, import_shared16.withoutImportant)(entry.value));
|
|
2530
|
-
if (!transformed.className) {
|
|
2531
|
-
return;
|
|
2532
|
-
}
|
|
2533
|
-
const important = (0, import_shared16.isImportant)(entry.value);
|
|
2534
|
-
const styles = important ? (0, import_shared16.markImportant)(transformed.styles) : transformed.styles;
|
|
2535
|
-
const parts = entry.cond ? entry.cond.split(StyleEncoder.conditionSeparator) : [];
|
|
2536
|
-
const className = this.formatSelector(parts, transformed.className);
|
|
2537
|
-
const classSelector = important ? `.${className}\\!` : `.${className}`;
|
|
2538
|
-
return {
|
|
2539
|
-
className,
|
|
2540
|
-
classSelector,
|
|
2541
|
-
styles,
|
|
2542
|
-
transformed,
|
|
2543
|
-
parts
|
|
2544
|
-
};
|
|
2545
|
-
};
|
|
2546
|
-
resolveCondition = (condition) => {
|
|
2547
|
-
if (condition.type === "multi-block") return [];
|
|
2548
|
-
if (Array.isArray(condition.raw)) {
|
|
2549
|
-
return condition.raw.map((c) => this.context.utility.tokens.resolveReference(c));
|
|
2550
|
-
}
|
|
2551
|
-
return this.context.utility.tokens.resolveReference(condition.raw);
|
|
2552
|
-
};
|
|
2553
|
-
/**
|
|
2554
|
-
* Expands multi-block conditions into separate sets of conditions.
|
|
2555
|
-
* Each block becomes an independent condition set that produces its own CSS block.
|
|
2556
|
-
* When multiple multi-block conditions are stacked (e.g. two custom multi-block
|
|
2557
|
-
* conditions used together), the cartesian product of all blocks is produced.
|
|
2558
|
-
* Returns null if no multi-block condition is found.
|
|
2559
|
-
*/
|
|
2560
|
-
expandMultiBlock(conditions) {
|
|
2561
|
-
if (!conditions.some((c) => c.type === "multi-block")) return null;
|
|
2562
|
-
const alternatives = conditions.map((c) => {
|
|
2563
|
-
if (c.type === "multi-block") {
|
|
2564
|
-
return c.value.map((block) => block.value.filter(Boolean));
|
|
2565
|
-
}
|
|
2566
|
-
return [[c]];
|
|
2567
|
-
});
|
|
2568
|
-
let combos = [[]];
|
|
2569
|
-
for (const slot of alternatives) {
|
|
2570
|
-
const next = [];
|
|
2571
|
-
for (const partial of combos) {
|
|
2572
|
-
for (const choice of slot) {
|
|
2573
|
-
next.push([...partial, ...choice]);
|
|
2574
|
-
}
|
|
2575
|
-
}
|
|
2576
|
-
combos = next;
|
|
2577
|
-
}
|
|
2578
|
-
return combos.map((combo) => sortConditionDetails(combo));
|
|
2579
|
-
}
|
|
2580
|
-
getAtomic = (hash) => {
|
|
2581
|
-
const cached = this.atomic_cache.get(hash);
|
|
2582
|
-
if (cached) return cached;
|
|
2583
|
-
const entry = getEntryFromHash(hash);
|
|
2584
|
-
const transformResult = this.getTransformResult(hash);
|
|
2585
|
-
if (!transformResult) return;
|
|
2586
|
-
const { className, classSelector, styles, transformed, parts } = transformResult;
|
|
2587
|
-
const basePath = [classSelector];
|
|
2588
|
-
const obj = {};
|
|
2589
|
-
let conditions;
|
|
2590
|
-
if (entry.cond) {
|
|
2591
|
-
conditions = this.context.conditions.sort(parts);
|
|
2592
|
-
const expanded = this.expandMultiBlock(conditions);
|
|
2593
|
-
if (expanded) {
|
|
2594
|
-
for (const blockConditions of expanded) {
|
|
2595
|
-
const path = basePath.concat(blockConditions.flatMap((c) => this.resolveCondition(c)));
|
|
2596
|
-
(0, import_shared16.deepSet)(obj, path, styles);
|
|
2597
|
-
}
|
|
2598
|
-
} else {
|
|
2599
|
-
const path = basePath.concat(conditions.flatMap((c) => this.resolveCondition(c)));
|
|
2600
|
-
(0, import_shared16.deepSet)(obj, path, styles);
|
|
2601
|
-
}
|
|
2602
|
-
} else {
|
|
2603
|
-
(0, import_shared16.deepSet)(obj, basePath, styles);
|
|
2604
|
-
}
|
|
2605
|
-
const styleResult = {
|
|
2606
|
-
result: obj,
|
|
2607
|
-
entry,
|
|
2608
|
-
hash,
|
|
2609
|
-
conditions,
|
|
2610
|
-
className,
|
|
2611
|
-
layer: transformed.layer
|
|
2612
|
-
};
|
|
2613
|
-
this.atomic_cache.set(hash, styleResult);
|
|
2614
|
-
return styleResult;
|
|
2615
|
-
};
|
|
2616
|
-
getGroup = (hashSet, key) => {
|
|
2617
|
-
const cached = this.group_cache.get(key);
|
|
2618
|
-
if (cached) return cached;
|
|
2619
|
-
let obj = {};
|
|
2620
|
-
const basePath = [];
|
|
2621
|
-
const details = [];
|
|
2622
|
-
const transform = this.context.utility.transform.bind(this.context.utility);
|
|
2623
|
-
hashSet.forEach((hash) => {
|
|
2624
|
-
const entry = getEntryFromHash(hash);
|
|
2625
|
-
const transformed = transform(entry.prop, (0, import_shared16.withoutImportant)(entry.value));
|
|
2626
|
-
if (!transformed.className) return;
|
|
2627
|
-
const important = (0, import_shared16.isImportant)(entry.value);
|
|
2628
|
-
const result2 = important ? (0, import_shared16.markImportant)(transformed.styles) : transformed.styles;
|
|
2629
|
-
const parts = entry.cond ? entry.cond.split(StyleEncoder.conditionSeparator) : [];
|
|
2630
|
-
let conditions;
|
|
2631
|
-
if (entry.cond) {
|
|
2632
|
-
conditions = this.context.conditions.sort(parts);
|
|
2633
|
-
}
|
|
2634
|
-
details.push({ hash, entry, conditions, result: result2 });
|
|
2635
|
-
});
|
|
2636
|
-
const sorted = sortStyleRules(details);
|
|
2637
|
-
sorted.forEach((value) => {
|
|
2638
|
-
if (value.conditions) {
|
|
2639
|
-
const expanded = this.expandMultiBlock(value.conditions);
|
|
2640
|
-
if (expanded) {
|
|
2641
|
-
for (const blockConditions of expanded) {
|
|
2642
|
-
const path = basePath.concat(blockConditions.flatMap((c) => this.resolveCondition(c)));
|
|
2643
|
-
obj = (0, import_shared16.deepSet)(obj, path, value.result);
|
|
2644
|
-
}
|
|
2645
|
-
} else {
|
|
2646
|
-
const path = basePath.concat(value.conditions.flatMap((c) => this.resolveCondition(c)));
|
|
2647
|
-
obj = (0, import_shared16.deepSet)(obj, path, value.result);
|
|
2648
|
-
}
|
|
2649
|
-
} else {
|
|
2650
|
-
obj = (0, import_shared16.deepSet)(obj, basePath, value.result);
|
|
2651
|
-
}
|
|
2652
|
-
});
|
|
2653
|
-
const result = { result: obj, hashSet, details, className: key };
|
|
2654
|
-
this.group_cache.set(key, result);
|
|
2655
|
-
return result;
|
|
2656
|
-
};
|
|
2657
|
-
getRecipeBase = (hashSet, recipeName, slot) => {
|
|
2658
|
-
const recipeConfig = this.context.recipes.getConfig(recipeName);
|
|
2659
|
-
if (!recipeConfig) return;
|
|
2660
|
-
const recipeNode = this.context.recipes.getRecipe(recipeName);
|
|
2661
|
-
if (!recipeNode) return;
|
|
2662
|
-
const className = "slots" in recipeConfig && slot ? this.context.recipes.getSlotKey(recipeNode.className, slot) : recipeNode.className;
|
|
2663
|
-
const cached = this.recipe_base_cache.get(className);
|
|
2664
|
-
if (cached) return cached;
|
|
2665
|
-
const selector = this.formatSelector([], className);
|
|
2666
|
-
const style = this.getGroup(hashSet, className);
|
|
2667
|
-
const result = Object.assign({}, style, {
|
|
2668
|
-
result: { ["." + selector]: style.result },
|
|
2669
|
-
recipe: recipeName,
|
|
2670
|
-
className,
|
|
2671
|
-
slot
|
|
2672
|
-
});
|
|
2673
|
-
this.recipe_base_cache.set(className, result);
|
|
2674
|
-
return result;
|
|
2675
|
-
};
|
|
2676
|
-
collectAtomic = (encoder) => {
|
|
2677
|
-
const atomic = [];
|
|
2678
|
-
encoder.atomic.forEach((item) => {
|
|
2679
|
-
const result = this.getAtomic(item);
|
|
2680
|
-
if (!result) return;
|
|
2681
|
-
atomic.push(result);
|
|
2682
|
-
});
|
|
2683
|
-
const sorted = sortStyleRules(atomic);
|
|
2684
|
-
sorted.forEach((styleResult) => {
|
|
2685
|
-
this.atomic.add(styleResult);
|
|
2686
|
-
this.classNames.set(styleResult.className, styleResult);
|
|
2687
|
-
});
|
|
2688
|
-
return this;
|
|
2689
|
-
};
|
|
2690
|
-
processClassName = (recipeName, hash) => {
|
|
2691
|
-
const result = this.getAtomic(hash);
|
|
2692
|
-
if (!result) return;
|
|
2693
|
-
const styleSet = (0, import_shared16.getOrCreateSet)(this.recipes, recipeName);
|
|
2694
|
-
styleSet.add(result);
|
|
2695
|
-
this.classNames.set(result.className, result);
|
|
2696
|
-
};
|
|
2697
|
-
collectRecipe = (encoder) => {
|
|
2698
|
-
encoder.recipes.forEach((hashSet, recipeName) => {
|
|
2699
|
-
const recipeConfig = this.context.recipes.getConfig(recipeName);
|
|
2700
|
-
if (!recipeConfig) return;
|
|
2701
|
-
hashSet.forEach((hash) => {
|
|
2702
|
-
if ("slots" in recipeConfig) {
|
|
2703
|
-
recipeConfig.slots.forEach((slot) => {
|
|
2704
|
-
const slotHash = hash + StyleEncoder.separator + "slot:" + slot;
|
|
2705
|
-
this.processClassName(recipeName, slotHash);
|
|
2706
|
-
});
|
|
2707
|
-
} else {
|
|
2708
|
-
this.processClassName(recipeName, hash);
|
|
2709
|
-
}
|
|
2710
|
-
});
|
|
2711
|
-
});
|
|
2712
|
-
};
|
|
2713
|
-
collectRecipeBase = (encoder) => {
|
|
2714
|
-
encoder.recipes_base.forEach((hashSet, recipeKey) => {
|
|
2715
|
-
const [recipeName, slot] = recipeKey.split(this.context.recipes.slotSeparator);
|
|
2716
|
-
const recipeConfig = this.context.recipes.getConfig(recipeName);
|
|
2717
|
-
if (!recipeConfig) return;
|
|
2718
|
-
const result = this.getRecipeBase(hashSet, recipeName, slot);
|
|
2719
|
-
if (!result) return;
|
|
2720
|
-
const styleSet = (0, import_shared16.getOrCreateSet)(this.recipes_base, recipeKey);
|
|
2721
|
-
styleSet.add(result);
|
|
2722
|
-
this.classNames.set(result.className, result);
|
|
2723
|
-
});
|
|
2724
|
-
};
|
|
2725
|
-
collectGrouped = (encoder) => {
|
|
2726
|
-
encoder.grouped.forEach((hashSet, groupId) => {
|
|
2727
|
-
const groupKey = "grouped:" + groupId;
|
|
2728
|
-
const style = this.getGroup(hashSet, groupKey);
|
|
2729
|
-
const shortHash = this.context.utility.toHash(["grouped", groupId], this.context.utility.defaultHashFn);
|
|
2730
|
-
const className = this.formatSelector([], shortHash);
|
|
2731
|
-
const result = {
|
|
2732
|
-
...style,
|
|
2733
|
-
className,
|
|
2734
|
-
result: { ["." + className]: style.result }
|
|
2735
|
-
};
|
|
2736
|
-
this.grouped.add(result);
|
|
2737
|
-
this.classNames.set(className, result);
|
|
2738
|
-
});
|
|
2739
|
-
};
|
|
2740
|
-
/**
|
|
2741
|
-
* Collect and re-create all styles and recipes objects from the style encoder
|
|
2742
|
-
* So that we can just iterate over them and transform resulting CSS objects into CSS strings
|
|
2743
|
-
*/
|
|
2744
|
-
collect = (encoder) => {
|
|
2745
|
-
this.collectAtomic(encoder);
|
|
2746
|
-
this.collectGrouped(encoder);
|
|
2747
|
-
this.collectRecipe(encoder);
|
|
2748
|
-
this.collectRecipeBase(encoder);
|
|
2749
|
-
return this;
|
|
2750
|
-
};
|
|
2751
|
-
getConfigRecipeResult = (recipeName) => {
|
|
2752
|
-
return {
|
|
2753
|
-
atomic: this.atomic,
|
|
2754
|
-
base: this.recipes_base.get(recipeName),
|
|
2755
|
-
variants: this.recipes.get(recipeName)
|
|
2756
|
-
};
|
|
2757
|
-
};
|
|
2758
|
-
getConfigSlotRecipeResult = (recipeName) => {
|
|
2759
|
-
const recipeConfig = this.context.recipes.getConfigOrThrow(recipeName);
|
|
2760
|
-
if (!Recipes.isSlotRecipeConfig(recipeConfig)) {
|
|
2761
|
-
throw new import_shared16.BambooError("UNKNOWN_RECIPE", `Recipe "${recipeName}" is not a slot recipe`);
|
|
2762
|
-
}
|
|
2763
|
-
const base = {};
|
|
2764
|
-
recipeConfig.slots.map((slot) => {
|
|
2765
|
-
const recipeKey = this.context.recipes.getSlotKey(recipeName, slot);
|
|
2766
|
-
base[slot] = this.recipes_base.get(recipeKey);
|
|
2767
|
-
});
|
|
2768
|
-
return {
|
|
2769
|
-
atomic: this.atomic,
|
|
2770
|
-
base,
|
|
2771
|
-
variants: this.recipes.get(recipeName)
|
|
2772
|
-
};
|
|
2773
|
-
};
|
|
2774
|
-
getRecipeResult = (recipeName) => {
|
|
2775
|
-
if (this.context.recipes.isSlotRecipe(recipeName)) {
|
|
2776
|
-
return this.getConfigSlotRecipeResult(recipeName);
|
|
2777
|
-
}
|
|
2778
|
-
return this.getConfigRecipeResult(recipeName);
|
|
2779
|
-
};
|
|
2780
|
-
};
|
|
2781
|
-
var entryKeys = ["cond", "recipe", "layer", "slot"];
|
|
2782
|
-
var getEntryFromHash = (hash) => {
|
|
2783
|
-
const parts = hash.split(StyleEncoder.separator);
|
|
2784
|
-
const prop = parts[0];
|
|
2785
|
-
const rawValue = parts[1].replace("value:", "");
|
|
2786
|
-
const value = parseValue(rawValue);
|
|
2787
|
-
const entry = { prop, value };
|
|
2788
|
-
parts.forEach((part) => {
|
|
2789
|
-
const key = entryKeys.find((k) => part.startsWith(k));
|
|
2790
|
-
if (key) {
|
|
2791
|
-
entry[key] = part.slice(key.length + 1);
|
|
2792
|
-
}
|
|
2793
|
-
});
|
|
2794
|
-
return entry;
|
|
2795
|
-
};
|
|
2796
|
-
var startsWithZero = /^0\d+$/;
|
|
2797
|
-
var parseValue = (value) => {
|
|
2798
|
-
if (startsWithZero.test(value)) {
|
|
2799
|
-
return value;
|
|
2800
|
-
}
|
|
2801
|
-
const asNumber = Number(value);
|
|
2802
|
-
if (!Number.isNaN(asNumber)) return asNumber;
|
|
2803
|
-
return castBoolean(value);
|
|
2804
|
-
};
|
|
2805
|
-
var castBoolean = (value) => {
|
|
2806
|
-
if (value === "true") return true;
|
|
2807
|
-
if (value === "false") return false;
|
|
2808
|
-
return value;
|
|
2809
|
-
};
|
|
2810
|
-
var pseudoElementRegex2 = /::[\w-]/;
|
|
2811
|
-
var sortConditionDetails = (conditions) => {
|
|
2812
|
-
const indexed = conditions.map((cond, i) => ({ cond, i }));
|
|
2813
|
-
indexed.sort((a, b) => {
|
|
2814
|
-
const aIsAtRule = a.cond.type === "at-rule";
|
|
2815
|
-
const bIsAtRule = b.cond.type === "at-rule";
|
|
2816
|
-
if (aIsAtRule && !bIsAtRule) return -1;
|
|
2817
|
-
if (!aIsAtRule && bIsAtRule) return 1;
|
|
2818
|
-
const aIsPseudo = typeof a.cond.raw === "string" && pseudoElementRegex2.test(a.cond.raw);
|
|
2819
|
-
const bIsPseudo = typeof b.cond.raw === "string" && pseudoElementRegex2.test(b.cond.raw);
|
|
2820
|
-
if (aIsPseudo !== bIsPseudo) return aIsPseudo ? 1 : -1;
|
|
2821
|
-
return a.i - b.i;
|
|
2822
|
-
});
|
|
2823
|
-
return indexed.map((item) => item.cond);
|
|
2824
|
-
};
|
|
2825
|
-
|
|
2826
|
-
// src/static-css.ts
|
|
2827
|
-
var StaticCss = class {
|
|
2828
|
-
constructor(context) {
|
|
2829
|
-
this.context = context;
|
|
2830
|
-
this.encoder = context.encoder;
|
|
2831
|
-
this.decoder = context.decoder;
|
|
2832
|
-
this.breakpointKeys = Object.keys(context.config.theme?.breakpoints ?? {});
|
|
2833
|
-
this.conditionKeys = Object.keys(context.config.conditions ?? {});
|
|
2834
|
-
}
|
|
2835
|
-
encoder;
|
|
2836
|
-
decoder;
|
|
2837
|
-
breakpointKeys;
|
|
2838
|
-
conditionKeys;
|
|
2839
|
-
// Wildcard expansion cache - this is the main performance optimization
|
|
2840
|
-
// Memoizing wildcard expansions avoids redundant token lookups
|
|
2841
|
-
wildcardCache = /* @__PURE__ */ new Map();
|
|
2842
|
-
clone() {
|
|
2843
|
-
this.encoder = this.encoder.clone();
|
|
2844
|
-
this.decoder = this.decoder.clone();
|
|
2845
|
-
return this;
|
|
2846
|
-
}
|
|
2847
|
-
formatCondition = (condition) => {
|
|
2848
|
-
return this.conditionKeys.includes(condition) ? `_${condition}` : condition;
|
|
2849
|
-
};
|
|
2850
|
-
getConditionalValues = (conditions, value) => {
|
|
2851
|
-
return conditions.reduce(
|
|
2852
|
-
(acc, key) => {
|
|
2853
|
-
const cond = this.formatCondition(key);
|
|
2854
|
-
return { ...acc, [cond]: value };
|
|
2855
|
-
},
|
|
2856
|
-
{ base: value }
|
|
2857
|
-
);
|
|
2858
|
-
};
|
|
2859
|
-
createRegex = () => {
|
|
2860
|
-
const classNames = Array.from(this.decoder.classNames.keys());
|
|
2861
|
-
const escapedClassNames = classNames.map((name) => (0, import_shared17.esc)(name));
|
|
2862
|
-
const pattern = `(${escapedClassNames.join("|")})`;
|
|
2863
|
-
return new RegExp(`\\b${pattern}\\b`, "g");
|
|
2864
|
-
};
|
|
2865
|
-
parse = (text) => {
|
|
2866
|
-
const regex = this.createRegex();
|
|
2867
|
-
const matches = text.match(regex);
|
|
2868
|
-
if (!matches) return [];
|
|
2869
|
-
return matches.map((match3) => match3.replace(".", ""));
|
|
2870
|
-
};
|
|
2871
|
-
/**
|
|
2872
|
-
* Get property keys with memoization for wildcard expansion
|
|
2873
|
-
* This is the main performance optimization - avoids redundant token lookups
|
|
2874
|
-
*/
|
|
2875
|
-
getCachedPropertyKeys = (property) => {
|
|
2876
|
-
const cached = this.wildcardCache.has(property);
|
|
2877
|
-
if (!cached) {
|
|
2878
|
-
const keys2 = this.context.utility.getPropertyKeys(property);
|
|
2879
|
-
this.wildcardCache.set(property, keys2);
|
|
2880
|
-
import_logger3.logger.debug("static_css:wildcard", `${property} -> ${keys2.length} values (memoized)`);
|
|
2881
|
-
} else {
|
|
2882
|
-
import_logger3.logger.debug("static_css:wildcard", `${property} (cache hit)`);
|
|
2883
|
-
}
|
|
2884
|
-
return this.wildcardCache.get(property);
|
|
2885
|
-
};
|
|
2886
|
-
/**
|
|
2887
|
-
* Get pattern property values with memoization
|
|
2888
|
-
*/
|
|
2889
|
-
getCachedPatternPropertyValues = (patternName, property) => {
|
|
2890
|
-
const cacheKey = `${patternName}:${property}`;
|
|
2891
|
-
const cached = this.wildcardCache.has(cacheKey);
|
|
2892
|
-
if (!cached) {
|
|
2893
|
-
const values = this.context.patterns.getPropertyValues(patternName, property) ?? [];
|
|
2894
|
-
this.wildcardCache.set(cacheKey, values);
|
|
2895
|
-
import_logger3.logger.debug("static_css:wildcard", `Pattern ${patternName}.${property} -> ${values.length} values (memoized)`);
|
|
2896
|
-
} else {
|
|
2897
|
-
import_logger3.logger.debug("static_css:wildcard", `Pattern ${patternName}.${property} (cache hit)`);
|
|
2898
|
-
}
|
|
2899
|
-
return this.wildcardCache.get(cacheKey);
|
|
2900
|
-
};
|
|
2901
|
-
getCssObjects = (entry, conditions) => {
|
|
2902
|
-
const [property, values] = entry;
|
|
2903
|
-
const propKeys = this.getCachedPropertyKeys(property);
|
|
2904
|
-
const computedValues = values.flatMap((value) => value === "*" ? propKeys : value);
|
|
2905
|
-
return computedValues.map((value) => ({
|
|
2906
|
-
[property]: conditions.length ? this.getConditionalValues(conditions, value) : value
|
|
2907
|
-
}));
|
|
2908
|
-
};
|
|
2909
|
-
getCssRuleObjects = (rule) => {
|
|
2910
|
-
const conditions = rule.conditions || [];
|
|
2911
|
-
if (rule.responsive) {
|
|
2912
|
-
conditions.push(...this.breakpointKeys);
|
|
2913
|
-
}
|
|
2914
|
-
const entries = Object.entries(rule.properties);
|
|
2915
|
-
return entries.flatMap((entry) => this.getCssObjects(entry, conditions));
|
|
2916
|
-
};
|
|
2917
|
-
getPatternObjects = (name, entry, conditions) => {
|
|
2918
|
-
const [property, values] = entry;
|
|
2919
|
-
const propValues = this.getCachedPatternPropertyValues(name, property);
|
|
2920
|
-
const computedValues = values.flatMap((value) => value === "*" ? propValues : value);
|
|
2921
|
-
return computedValues.map((patternValue) => {
|
|
2922
|
-
const value = this.context.patterns.transform(name, { [property]: patternValue });
|
|
2923
|
-
const conditionalValues = this.getConditionalValues(conditions, value);
|
|
2924
|
-
return conditions.length ? conditionalValues : value;
|
|
2925
|
-
});
|
|
2926
|
-
};
|
|
2927
|
-
getPatternRuleObjects = (name, pattern) => {
|
|
2928
|
-
const details = this.context.patterns.details.find((d) => d.baseName === name);
|
|
2929
|
-
if (!details) return [];
|
|
2930
|
-
const useAllKeys = pattern === "*";
|
|
2931
|
-
let props = {};
|
|
2932
|
-
if (useAllKeys) {
|
|
2933
|
-
props = Object.fromEntries((details.props ?? []).map((key) => [key, ["*"]]));
|
|
2934
|
-
}
|
|
2935
|
-
const { conditions = [], responsive = false, properties = props } = useAllKeys ? {} : pattern;
|
|
2936
|
-
if (responsive) {
|
|
2937
|
-
conditions.push(...this.breakpointKeys);
|
|
2938
|
-
}
|
|
2939
|
-
const entries = Object.entries(properties);
|
|
2940
|
-
return entries.flatMap((entry) => this.getPatternObjects(name, entry, conditions));
|
|
2941
|
-
};
|
|
2942
|
-
getRecipeNode = (name) => {
|
|
2943
|
-
return this.context.recipes.details.find((detail) => detail.baseName === name);
|
|
2944
|
-
};
|
|
2945
|
-
getRecipeRuleObjects = (name, recipe, recipeNode) => {
|
|
2946
|
-
const recipeKeys = recipeNode.variantKeyMap;
|
|
2947
|
-
if (!recipeKeys) return [];
|
|
2948
|
-
const useAllKeys = recipe === "*";
|
|
2949
|
-
const { conditions = [], responsive, ...variants } = useAllKeys ? recipeKeys : recipe;
|
|
2950
|
-
if (responsive) {
|
|
2951
|
-
conditions.push(...this.breakpointKeys);
|
|
2952
|
-
}
|
|
2953
|
-
return Object.entries(variants).flatMap(([variant, values]) => {
|
|
2954
|
-
if (!Array.isArray(values)) return [];
|
|
2955
|
-
const computedValues = values.flatMap((value) => value === "*" ? recipeKeys[variant] : value);
|
|
2956
|
-
return computedValues.map((value) => {
|
|
2957
|
-
const conditionalValues = this.getConditionalValues(conditions, value);
|
|
2958
|
-
return { [name]: { [variant]: conditions.length ? conditionalValues : value } };
|
|
2959
|
-
});
|
|
2960
|
-
});
|
|
2961
|
-
};
|
|
2962
|
-
getRecipeCompoundVariantCssObjects = (recipeNode) => {
|
|
2963
|
-
const cssRules = [];
|
|
2964
|
-
const { compoundVariants } = recipeNode.config;
|
|
2965
|
-
if (!compoundVariants) return cssRules;
|
|
2966
|
-
compoundVariants.forEach((compoundVariant) => {
|
|
2967
|
-
const css = compoundVariant.css;
|
|
2968
|
-
const isSlot = "slots" in recipeNode.config && recipeNode.config.slots.length;
|
|
2969
|
-
if (isSlot) {
|
|
2970
|
-
Object.values(css).forEach((styles) => {
|
|
2971
|
-
Object.entries(styles).forEach(([prop, value]) => {
|
|
2972
|
-
cssRules.push({ [prop]: value });
|
|
2973
|
-
});
|
|
2974
|
-
});
|
|
2975
|
-
} else {
|
|
2976
|
-
Object.entries(css).forEach(([prop, value]) => {
|
|
2977
|
-
cssRules.push({ [prop]: value });
|
|
2978
|
-
});
|
|
2979
|
-
}
|
|
2980
|
-
});
|
|
2981
|
-
return cssRules;
|
|
2982
|
-
};
|
|
2983
|
-
/**
|
|
2984
|
-
* This transforms a static css config into the same format as in the ParserResult,
|
|
2985
|
-
* so that it can be processed by the same logic as styles found in app code.
|
|
2986
|
-
*
|
|
2987
|
-
* e.g.
|
|
2988
|
-
* @example { css: [{ color: ['red', 'blue'] }] } => { css: [{ color: 'red }, { color: 'blue }] }
|
|
2989
|
-
* @example { css: [{ color: ['red'], conditions: ['md'] }] } => { css: [{ color: { base: 'red', md: 'red' } }] }
|
|
2990
|
-
*
|
|
2991
|
-
*/
|
|
2992
|
-
getStyleObjects(options) {
|
|
2993
|
-
const { css = [], patterns = {} } = options;
|
|
2994
|
-
const results = {
|
|
2995
|
-
css: [],
|
|
2996
|
-
recipes: [],
|
|
2997
|
-
patterns: []
|
|
2998
|
-
};
|
|
2999
|
-
css.forEach((rule) => {
|
|
3000
|
-
const cssObjects = this.getCssRuleObjects(rule);
|
|
3001
|
-
results.css.push(...cssObjects);
|
|
3002
|
-
});
|
|
3003
|
-
const recipes = options.recipes ?? {};
|
|
3004
|
-
Object.entries(recipes).forEach(([recipe, rules]) => {
|
|
3005
|
-
const recipeNode = this.getRecipeNode(recipe);
|
|
3006
|
-
if (!recipeNode) return;
|
|
3007
|
-
results.recipes.push({ [recipe]: {} });
|
|
3008
|
-
if (recipeNode.config.compoundVariants) {
|
|
3009
|
-
results.css.push(...this.getRecipeCompoundVariantCssObjects(recipeNode));
|
|
3010
|
-
}
|
|
3011
|
-
rules.forEach((rule) => {
|
|
3012
|
-
results.recipes.push(...this.getRecipeRuleObjects(recipe, rule, recipeNode));
|
|
3013
|
-
});
|
|
3014
|
-
});
|
|
3015
|
-
Object.entries(patterns).forEach(([pattern, rules]) => {
|
|
3016
|
-
rules.forEach((rule) => {
|
|
3017
|
-
results.patterns.push(...this.getPatternRuleObjects(pattern, rule));
|
|
3018
|
-
});
|
|
3019
|
-
});
|
|
3020
|
-
return results;
|
|
3021
|
-
}
|
|
3022
|
-
process = (options, stylesheet) => {
|
|
3023
|
-
const { context } = this;
|
|
3024
|
-
const sheet = stylesheet ?? context.createSheet();
|
|
3025
|
-
const isClonedInstance = this.encoder !== context.encoder;
|
|
3026
|
-
const encoder = isClonedInstance ? context.encoder.clone() : this.encoder;
|
|
3027
|
-
const decoder = isClonedInstance ? context.decoder.clone() : this.decoder;
|
|
3028
|
-
const staticCss = {
|
|
3029
|
-
...options,
|
|
3030
|
-
recipes: { ...typeof options.recipes === "string" ? {} : options.recipes }
|
|
3031
|
-
};
|
|
3032
|
-
const { theme = {} } = context.config;
|
|
3033
|
-
const recipeConfigs = Object.assign({}, theme.recipes, theme.slotRecipes);
|
|
3034
|
-
const useAllRecipes = options.recipes === "*";
|
|
3035
|
-
Object.entries(recipeConfigs).forEach(([name, recipe]) => {
|
|
3036
|
-
if (useAllRecipes) {
|
|
3037
|
-
staticCss.recipes[name] = ["*"];
|
|
3038
|
-
} else if (recipe.staticCss) {
|
|
3039
|
-
staticCss.recipes[name] = recipe.staticCss;
|
|
3040
|
-
}
|
|
3041
|
-
});
|
|
3042
|
-
import_logger3.logger.debug("static_css:process", `Processing staticCss`);
|
|
3043
|
-
const results = this.getStyleObjects(staticCss);
|
|
3044
|
-
import_logger3.logger.debug(
|
|
3045
|
-
"static_css:process",
|
|
3046
|
-
`Generated style objects: ${results.css.length} css, ${results.recipes.length} recipes, ${results.patterns.length} patterns`
|
|
3047
|
-
);
|
|
3048
|
-
results.css.forEach((css) => {
|
|
3049
|
-
encoder.hashStyleObject(encoder.atomic, css);
|
|
3050
|
-
});
|
|
3051
|
-
results.recipes.forEach((result) => {
|
|
3052
|
-
Object.entries(result).forEach(([name, value]) => {
|
|
3053
|
-
encoder.processRecipe(name, value);
|
|
3054
|
-
});
|
|
3055
|
-
});
|
|
3056
|
-
results.patterns.forEach((result) => {
|
|
3057
|
-
encoder.hashStyleObject(encoder.atomic, result);
|
|
3058
|
-
});
|
|
3059
|
-
sheet.processDecoder(decoder.collect(encoder));
|
|
3060
|
-
return {
|
|
3061
|
-
results,
|
|
3062
|
-
sheet
|
|
3063
|
-
};
|
|
3064
|
-
};
|
|
3065
|
-
};
|
|
3066
|
-
|
|
3067
|
-
// src/stylesheet.ts
|
|
3068
|
-
var import_postcss_cascade_layers = __toESM(require("@csstools/postcss-cascade-layers"));
|
|
3069
|
-
var import_logger4 = require("@bamboocss/logger");
|
|
3070
|
-
var import_postcss6 = __toESM(require("postcss"));
|
|
3071
|
-
|
|
3072
|
-
// src/optimize.ts
|
|
3073
|
-
var import_postcss5 = __toESM(require("postcss"));
|
|
3074
|
-
var import_postcss_nested2 = __toESM(require("postcss-nested"));
|
|
3075
|
-
|
|
3076
|
-
// src/plugins/optimize-postcss.ts
|
|
3077
|
-
var import_postcss4 = __toESM(require("postcss"));
|
|
3078
|
-
var import_postcss_discard_duplicates = __toESM(require("postcss-discard-duplicates"));
|
|
3079
|
-
var import_postcss_discard_empty = __toESM(require("postcss-discard-empty"));
|
|
3080
|
-
var import_postcss_minify_selectors = __toESM(require("postcss-minify-selectors"));
|
|
3081
|
-
var import_postcss_nested = __toESM(require("postcss-nested"));
|
|
3082
|
-
var import_postcss_normalize_whitespace = __toESM(require("postcss-normalize-whitespace"));
|
|
3083
|
-
|
|
3084
|
-
// src/plugins/merge-rules.ts
|
|
3085
|
-
var vendorPrefix = /-(ah|apple|atsc|epub|hp|khtml|moz|ms|o|rim|ro|tc|wap|webkit|xv)-/;
|
|
3086
|
-
var findMsInputPlaceholder = (selector) => ~selector.search(/-ms-input-placeholder/i);
|
|
3087
|
-
function filterPrefixes(selector) {
|
|
3088
|
-
return selector.match(vendorPrefix);
|
|
3089
|
-
}
|
|
3090
|
-
function sameVendor(selectorsA, selectorsB) {
|
|
3091
|
-
const same = (selectors) => selectors.map((s) => filterPrefixes(s)?.join() ?? "").join(",");
|
|
3092
|
-
const findMsVendor = (selectors) => selectors.find((s) => findMsInputPlaceholder(s));
|
|
3093
|
-
return same(selectorsA) === same(selectorsB) && !(findMsVendor(selectorsA) && findMsVendor(selectorsB));
|
|
3094
|
-
}
|
|
3095
|
-
function noVendor(selector) {
|
|
3096
|
-
return !vendorPrefix.test(selector);
|
|
3097
|
-
}
|
|
3098
|
-
function checkMatch(nodeA, nodeB) {
|
|
3099
|
-
if (nodeA.type === "atrule" && nodeB.type === "atrule") {
|
|
3100
|
-
return nodeA.params === nodeB.params && nodeA.name?.toLowerCase() === nodeB.name?.toLowerCase();
|
|
3101
|
-
}
|
|
3102
|
-
return nodeA.type === nodeB.type;
|
|
3103
|
-
}
|
|
3104
|
-
function sameParent(nodeA, nodeB) {
|
|
3105
|
-
if (!nodeA.parent) {
|
|
3106
|
-
return !nodeB.parent;
|
|
3107
|
-
}
|
|
3108
|
-
if (!nodeB.parent) {
|
|
3109
|
-
return false;
|
|
3110
|
-
}
|
|
3111
|
-
if (!checkMatch(nodeA.parent, nodeB.parent)) {
|
|
3112
|
-
return false;
|
|
3113
|
-
}
|
|
3114
|
-
return sameParent(nodeA.parent, nodeB.parent);
|
|
3115
|
-
}
|
|
3116
|
-
function declarationIsEqual(a, b) {
|
|
3117
|
-
return a.important === b.important && a.prop === b.prop && a.value === b.value;
|
|
3118
|
-
}
|
|
3119
|
-
function indexOfDeclaration(array, decl) {
|
|
3120
|
-
return array.findIndex((d) => declarationIsEqual(d, decl));
|
|
3121
|
-
}
|
|
3122
|
-
function intersect(a, b, not = false) {
|
|
3123
|
-
return a.filter((c) => {
|
|
3124
|
-
const index = indexOfDeclaration(b, c) !== -1;
|
|
3125
|
-
return not ? !index : index;
|
|
3126
|
-
});
|
|
3127
|
-
}
|
|
3128
|
-
function sameDeclarationsAndOrder(a, b) {
|
|
3129
|
-
if (a.length !== b.length) return false;
|
|
3130
|
-
return a.every((d, index) => declarationIsEqual(d, b[index]));
|
|
3131
|
-
}
|
|
3132
|
-
function isRuleOrAtRule(node) {
|
|
3133
|
-
return node.type === "rule" || node.type === "atrule";
|
|
3134
|
-
}
|
|
3135
|
-
function isDeclaration(node) {
|
|
3136
|
-
return node.type === "decl";
|
|
3137
|
-
}
|
|
3138
|
-
function getDecls(rule) {
|
|
3139
|
-
return rule.nodes.filter(isDeclaration);
|
|
3140
|
-
}
|
|
3141
|
-
var joinSelectors = (...rules) => rules.map((s) => s.selector).join(",");
|
|
3142
|
-
function ruleLength(...rules) {
|
|
3143
|
-
return rules.map((r) => r.nodes.length ? String(r) : "").join("").length;
|
|
3144
|
-
}
|
|
3145
|
-
function splitProp(prop) {
|
|
3146
|
-
const parts = prop.split("-");
|
|
3147
|
-
if (prop[0] !== "-") {
|
|
3148
|
-
return { prefix: "", base: parts[0], rest: parts.slice(1) };
|
|
3149
|
-
}
|
|
3150
|
-
if (prop[1] === "-") {
|
|
3151
|
-
return { prefix: null, base: null, rest: [prop] };
|
|
3152
|
-
}
|
|
3153
|
-
return {
|
|
3154
|
-
prefix: parts[1],
|
|
3155
|
-
base: parts[2],
|
|
3156
|
-
rest: parts.slice(3)
|
|
3157
|
-
};
|
|
3158
|
-
}
|
|
3159
|
-
function isConflictingProp(propA, propB) {
|
|
3160
|
-
if (propA === propB) return true;
|
|
3161
|
-
const a = splitProp(propA);
|
|
3162
|
-
const b = splitProp(propB);
|
|
3163
|
-
if (!a.base && !b.base) return true;
|
|
3164
|
-
if (a.base !== b.base && a.base !== "place" && b.base !== "place") {
|
|
3165
|
-
return false;
|
|
3166
|
-
}
|
|
3167
|
-
if (a.rest.length !== b.rest.length) return true;
|
|
3168
|
-
if (a.base === "border") {
|
|
3169
|
-
const allRestProps = /* @__PURE__ */ new Set([...a.rest, ...b.rest]);
|
|
3170
|
-
if (allRestProps.has("image") || allRestProps.has("width") || allRestProps.has("color") || allRestProps.has("style")) {
|
|
3171
|
-
return true;
|
|
3172
|
-
}
|
|
3173
|
-
}
|
|
3174
|
-
return a.rest.every((s, index) => b.rest[index] === s);
|
|
3175
|
-
}
|
|
3176
|
-
function mergeParents(first, second) {
|
|
3177
|
-
if (!first.parent || !second.parent) return false;
|
|
3178
|
-
if (first.parent === second.parent) return false;
|
|
3179
|
-
second.remove();
|
|
3180
|
-
first.parent.append(second);
|
|
3181
|
-
return true;
|
|
3182
|
-
}
|
|
3183
|
-
function canMerge(ruleA, ruleB) {
|
|
3184
|
-
const a = ruleA.selectors;
|
|
3185
|
-
const b = ruleB.selectors;
|
|
3186
|
-
const selectors = a.concat(b);
|
|
3187
|
-
const parent = sameParent(ruleA, ruleB);
|
|
3188
|
-
if (parent && ruleA.parent && ruleA.parent.type === "atrule" && ruleA.parent.name?.includes("keyframes")) {
|
|
3189
|
-
return false;
|
|
3190
|
-
}
|
|
3191
|
-
if (ruleA.some(isRuleOrAtRule) || ruleB.some(isRuleOrAtRule)) {
|
|
3192
|
-
return false;
|
|
3193
|
-
}
|
|
3194
|
-
return parent && (selectors.every(noVendor) || sameVendor(a, b));
|
|
3195
|
-
}
|
|
3196
|
-
function partialMerge(first, second) {
|
|
3197
|
-
let intersection = intersect(getDecls(first), getDecls(second));
|
|
3198
|
-
if (intersection.length === 0) return second;
|
|
3199
|
-
let nextRule = second.next();
|
|
3200
|
-
if (!nextRule) {
|
|
3201
|
-
const parentSibling = second.parent?.next();
|
|
3202
|
-
nextRule = parentSibling?.nodes?.[0];
|
|
3203
|
-
}
|
|
3204
|
-
if (nextRule && nextRule.type === "rule" && canMerge(second, nextRule)) {
|
|
3205
|
-
const nextIntersection = intersect(getDecls(second), getDecls(nextRule));
|
|
3206
|
-
if (nextIntersection.length > intersection.length) {
|
|
3207
|
-
mergeParents(second, nextRule);
|
|
3208
|
-
first = second;
|
|
3209
|
-
second = nextRule;
|
|
3210
|
-
intersection = nextIntersection;
|
|
3211
|
-
}
|
|
3212
|
-
}
|
|
3213
|
-
const firstDecls = getDecls(first);
|
|
3214
|
-
intersection = intersection.filter((decl, intersectIndex) => {
|
|
3215
|
-
const indexOfDecl = indexOfDeclaration(firstDecls, decl);
|
|
3216
|
-
const nextConflictInFirst = firstDecls.slice(indexOfDecl + 1).filter((d) => isConflictingProp(d.prop, decl.prop));
|
|
3217
|
-
if (nextConflictInFirst.length === 0) return true;
|
|
3218
|
-
const nextConflictInIntersection = intersection.slice(intersectIndex + 1).filter((d) => isConflictingProp(d.prop, decl.prop));
|
|
3219
|
-
if (nextConflictInFirst.length !== nextConflictInIntersection.length) {
|
|
3220
|
-
return false;
|
|
3221
|
-
}
|
|
3222
|
-
return nextConflictInFirst.every((d, index) => declarationIsEqual(d, nextConflictInIntersection[index]));
|
|
3223
|
-
});
|
|
3224
|
-
const secondDecls = getDecls(second);
|
|
3225
|
-
intersection = intersection.filter((decl) => {
|
|
3226
|
-
const nextConflictIndex = secondDecls.findIndex((d) => isConflictingProp(d.prop, decl.prop));
|
|
3227
|
-
if (nextConflictIndex === -1) return false;
|
|
3228
|
-
if (!declarationIsEqual(secondDecls[nextConflictIndex], decl)) {
|
|
3229
|
-
return false;
|
|
3230
|
-
}
|
|
3231
|
-
if (decl.prop.toLowerCase() !== "direction" && decl.prop.toLowerCase() !== "unicode-bidi" && secondDecls.some((d) => d.prop.toLowerCase() === "all")) {
|
|
3232
|
-
return false;
|
|
3233
|
-
}
|
|
3234
|
-
secondDecls.splice(nextConflictIndex, 1);
|
|
3235
|
-
return true;
|
|
3236
|
-
});
|
|
3237
|
-
if (intersection.length === 0) return second;
|
|
3238
|
-
const receivingBlock = second.clone();
|
|
3239
|
-
receivingBlock.selector = joinSelectors(first, second);
|
|
3240
|
-
receivingBlock.nodes = [];
|
|
3241
|
-
second.parent.insertBefore(second, receivingBlock);
|
|
3242
|
-
const firstClone = first.clone();
|
|
3243
|
-
const secondClone = second.clone();
|
|
3244
|
-
function moveDecl(callback) {
|
|
3245
|
-
return (decl) => {
|
|
3246
|
-
if (indexOfDeclaration(intersection, decl) !== -1) {
|
|
3247
|
-
callback(decl);
|
|
3248
|
-
}
|
|
3249
|
-
};
|
|
3250
|
-
}
|
|
3251
|
-
firstClone.walkDecls(
|
|
3252
|
-
moveDecl((decl) => {
|
|
3253
|
-
decl.remove();
|
|
3254
|
-
receivingBlock.append(decl);
|
|
3255
|
-
})
|
|
3256
|
-
);
|
|
3257
|
-
secondClone.walkDecls(moveDecl((decl) => decl.remove()));
|
|
3258
|
-
const merged = ruleLength(firstClone, receivingBlock, secondClone);
|
|
3259
|
-
const original = ruleLength(first, second);
|
|
3260
|
-
if (merged < original) {
|
|
3261
|
-
first.replaceWith(firstClone);
|
|
3262
|
-
second.replaceWith(secondClone);
|
|
3263
|
-
[firstClone, receivingBlock, secondClone].forEach((r) => {
|
|
3264
|
-
if (r.nodes.length === 0) r.remove();
|
|
3265
|
-
});
|
|
3266
|
-
if (!secondClone.parent) return receivingBlock;
|
|
3267
|
-
return secondClone;
|
|
3268
|
-
} else {
|
|
3269
|
-
receivingBlock.remove();
|
|
3270
|
-
return second;
|
|
3271
|
-
}
|
|
3272
|
-
}
|
|
3273
|
-
function selectorMerger() {
|
|
3274
|
-
let cache = null;
|
|
3275
|
-
return function(rule) {
|
|
3276
|
-
if (!cache || !canMerge(rule, cache)) {
|
|
3277
|
-
cache = rule;
|
|
3278
|
-
return;
|
|
3279
|
-
}
|
|
3280
|
-
if (cache === rule) {
|
|
3281
|
-
cache = rule;
|
|
3282
|
-
return;
|
|
3283
|
-
}
|
|
3284
|
-
mergeParents(cache, rule);
|
|
3285
|
-
if (sameDeclarationsAndOrder(getDecls(rule), getDecls(cache))) {
|
|
3286
|
-
rule.selector = joinSelectors(cache, rule);
|
|
3287
|
-
cache.remove();
|
|
3288
|
-
cache = rule;
|
|
3289
|
-
return;
|
|
3290
|
-
}
|
|
3291
|
-
if (cache.selector === rule.selector) {
|
|
3292
|
-
const cached = getDecls(cache);
|
|
3293
|
-
rule.walk((node) => {
|
|
3294
|
-
if (node.type === "decl" && indexOfDeclaration(cached, node) !== -1) {
|
|
3295
|
-
node.remove();
|
|
3296
|
-
return;
|
|
3297
|
-
}
|
|
3298
|
-
cache.append(node);
|
|
3299
|
-
});
|
|
3300
|
-
rule.remove();
|
|
3301
|
-
return;
|
|
3302
|
-
}
|
|
3303
|
-
cache = partialMerge(cache, rule);
|
|
3304
|
-
};
|
|
3305
|
-
}
|
|
3306
|
-
function mergeRules() {
|
|
3307
|
-
return {
|
|
3308
|
-
postcssPlugin: "postcss-merge-rules",
|
|
3309
|
-
OnceExit(css) {
|
|
3310
|
-
css.walkRules(selectorMerger());
|
|
3311
|
-
}
|
|
3312
|
-
};
|
|
3313
|
-
}
|
|
3314
|
-
mergeRules.postcss = true;
|
|
3315
|
-
|
|
3316
|
-
// src/plugins/prettify.ts
|
|
3317
|
-
function prettifyNode(node, indent = 0) {
|
|
3318
|
-
node.each && node.each((child, i) => {
|
|
3319
|
-
if (!child.raws.before || !child.raws.before.trim() || child.raws.before.includes("\n")) {
|
|
3320
|
-
child.raws.before = `
|
|
3321
|
-
${node.type !== "rule" && i > 0 ? "\n" : ""}${" ".repeat(indent)}`;
|
|
3322
|
-
}
|
|
3323
|
-
prettifyNode(child, indent + 1);
|
|
3324
|
-
});
|
|
3325
|
-
}
|
|
3326
|
-
function prettify() {
|
|
3327
|
-
return (root) => {
|
|
3328
|
-
prettifyNode(root);
|
|
3329
|
-
if (root.first) {
|
|
3330
|
-
root.first.raws.before = "";
|
|
3331
|
-
}
|
|
3332
|
-
};
|
|
3333
|
-
}
|
|
3334
|
-
prettify.postcssPlugin = "bamboo-prettify";
|
|
3335
|
-
|
|
3336
|
-
// src/plugins/optimize-postcss.ts
|
|
3337
|
-
function optimizePostCss(code, options = {}) {
|
|
3338
|
-
const { minify = false } = options;
|
|
3339
|
-
const plugins = [
|
|
3340
|
-
(0, import_postcss_nested.default)(),
|
|
3341
|
-
(0, import_postcss_discard_duplicates.default)(),
|
|
3342
|
-
mergeRules(),
|
|
3343
|
-
(0, import_postcss_discard_empty.default)()
|
|
3344
|
-
];
|
|
3345
|
-
if (minify) {
|
|
3346
|
-
plugins.push((0, import_postcss_normalize_whitespace.default)(), (0, import_postcss_minify_selectors.default)());
|
|
3347
|
-
} else {
|
|
3348
|
-
plugins.push(prettify());
|
|
3349
|
-
}
|
|
3350
|
-
const { css } = (0, import_postcss4.default)(plugins).process(code);
|
|
3351
|
-
return css;
|
|
3352
|
-
}
|
|
3353
|
-
|
|
3354
|
-
// src/optimize.ts
|
|
3355
|
-
function optimizeCss(code, options = {}) {
|
|
3356
|
-
const { hooks } = options;
|
|
3357
|
-
const css = typeof code === "string" ? code : code.toString();
|
|
3358
|
-
if (hooks?.["css:optimize"]) {
|
|
3359
|
-
const result = hooks["css:optimize"]({
|
|
3360
|
-
css,
|
|
3361
|
-
minify: options.minify,
|
|
3362
|
-
browserslist: options.browserslist
|
|
3363
|
-
});
|
|
3364
|
-
if (result !== void 0) {
|
|
3365
|
-
return result;
|
|
3366
|
-
}
|
|
3367
|
-
}
|
|
3368
|
-
return optimizePostCss(code, options);
|
|
3369
|
-
}
|
|
3370
|
-
function expandNestedCss(code) {
|
|
3371
|
-
const { css } = (0, import_postcss5.default)([(0, import_postcss_nested2.default)(), prettify()]).process(code);
|
|
3372
|
-
return css;
|
|
3373
|
-
}
|
|
3374
|
-
|
|
3375
|
-
// src/plugins/sort-mq.ts
|
|
3376
|
-
var import_ts_pattern = require("ts-pattern");
|
|
3377
|
-
var atRuleName = import_ts_pattern.P.union("media", "container");
|
|
3378
|
-
function sortMediaQueries() {
|
|
3379
|
-
const inner = (root) => {
|
|
3380
|
-
root.nodes?.sort((a, b) => {
|
|
3381
|
-
return (0, import_ts_pattern.match)({ a, b }).with(
|
|
3382
|
-
{
|
|
3383
|
-
a: { type: "atrule", name: atRuleName },
|
|
3384
|
-
b: { type: "atrule", name: atRuleName }
|
|
3385
|
-
},
|
|
3386
|
-
({ a: a2, b: b2 }) => {
|
|
3387
|
-
return sortAtRules(a2.params, b2.params);
|
|
3388
|
-
}
|
|
3389
|
-
).with({ a: { type: "atrule", name: atRuleName }, b: import_ts_pattern.P.any }, () => {
|
|
3390
|
-
return 1;
|
|
3391
|
-
}).with({ a: import_ts_pattern.P.any, b: { type: "atrule", name: atRuleName } }, () => {
|
|
3392
|
-
return -1;
|
|
3393
|
-
}).otherwise(() => {
|
|
3394
|
-
return 0;
|
|
3395
|
-
});
|
|
3396
|
-
});
|
|
3397
|
-
root.nodes?.forEach((node) => {
|
|
3398
|
-
if ("nodes" in node) {
|
|
3399
|
-
inner(node);
|
|
3400
|
-
}
|
|
3401
|
-
});
|
|
3402
|
-
};
|
|
3403
|
-
return inner;
|
|
3404
|
-
}
|
|
3405
|
-
sortMediaQueries.postcssPlugin = "bamboo-sort-mq";
|
|
3406
|
-
|
|
3407
|
-
// src/stylesheet.ts
|
|
3408
|
-
var Stylesheet = class {
|
|
3409
|
-
constructor(context) {
|
|
3410
|
-
this.context = context;
|
|
3411
|
-
}
|
|
3412
|
-
get layers() {
|
|
3413
|
-
return this.context.layers;
|
|
3414
|
-
}
|
|
3415
|
-
getLayer(layer) {
|
|
3416
|
-
return this.context.layers[layer];
|
|
3417
|
-
}
|
|
3418
|
-
process(options) {
|
|
3419
|
-
const layer = this.getLayer(options.layer);
|
|
3420
|
-
if (!layer) return;
|
|
3421
|
-
const { styles } = options;
|
|
3422
|
-
if (typeof styles !== "object") return;
|
|
3423
|
-
try {
|
|
3424
|
-
layer.append(stringify(styles));
|
|
3425
|
-
} catch (error) {
|
|
3426
|
-
if (error instanceof import_postcss6.CssSyntaxError) {
|
|
3427
|
-
import_logger4.logger.error("sheet:process", error.showSourceCode(true));
|
|
3428
|
-
} else {
|
|
3429
|
-
import_logger4.logger.caughtError("sheet:process", "Failed to process styles", error);
|
|
3430
|
-
}
|
|
3431
|
-
}
|
|
3432
|
-
return;
|
|
3433
|
-
}
|
|
3434
|
-
serialize = (styles) => {
|
|
3435
|
-
return serializeStyles(this.context, styles);
|
|
3436
|
-
};
|
|
3437
|
-
processResetCss = (styles) => {
|
|
3438
|
-
const result = this.serialize(styles);
|
|
3439
|
-
let css = stringify(result);
|
|
3440
|
-
if (this.context.hooks["cssgen:done"]) {
|
|
3441
|
-
css = this.context.hooks["cssgen:done"]({ artifact: "reset", content: css }) ?? css;
|
|
3442
|
-
}
|
|
3443
|
-
this.context.layers.reset.append(css);
|
|
3444
|
-
};
|
|
3445
|
-
processGlobalCss = (styles) => {
|
|
3446
|
-
const result = this.serialize(styles);
|
|
3447
|
-
let css = stringify(result);
|
|
3448
|
-
css += this.context.globalVars.toString();
|
|
3449
|
-
css += this.context.globalFontface.toString();
|
|
3450
|
-
css += this.context.globalPositionTry.toString();
|
|
3451
|
-
if (this.context.hooks["cssgen:done"]) {
|
|
3452
|
-
css = this.context.hooks["cssgen:done"]({ artifact: "global", content: css }) ?? css;
|
|
3453
|
-
}
|
|
3454
|
-
this.context.layers.base.append(css);
|
|
3455
|
-
};
|
|
3456
|
-
processCss = (styles, layer) => {
|
|
3457
|
-
if (!styles) return;
|
|
3458
|
-
this.process({ styles, layer });
|
|
3459
|
-
};
|
|
3460
|
-
processDecoder = (decoder) => {
|
|
3461
|
-
sortStyleRules([...decoder.atomic]).forEach((css) => {
|
|
3462
|
-
this.processCss(css.result, css.layer ?? "utilities");
|
|
3463
|
-
});
|
|
3464
|
-
decoder.grouped.forEach((grouped) => {
|
|
3465
|
-
this.processCss(grouped.result, "utilities");
|
|
3466
|
-
});
|
|
3467
|
-
decoder.recipes.forEach((recipeSet) => {
|
|
3468
|
-
recipeSet.forEach((recipe) => {
|
|
3469
|
-
this.processCss(recipe.result, recipe.entry.slot ? "recipes_slots" : "recipes");
|
|
3470
|
-
});
|
|
3471
|
-
});
|
|
3472
|
-
decoder.recipes_base.forEach((recipeSet) => {
|
|
3473
|
-
recipeSet.forEach((recipe) => {
|
|
3474
|
-
this.processCss(recipe.result, recipe.slot ? "recipes_slots_base" : "recipes_base");
|
|
3475
|
-
});
|
|
3476
|
-
});
|
|
3477
|
-
};
|
|
3478
|
-
/**
|
|
3479
|
-
* Process only the styles for a specific recipe from the decoder
|
|
3480
|
-
*/
|
|
3481
|
-
processDecoderForRecipe = (decoder, recipeName) => {
|
|
3482
|
-
const recipeSet = decoder.recipes.get(recipeName);
|
|
3483
|
-
if (recipeSet) {
|
|
3484
|
-
recipeSet.forEach((recipe) => {
|
|
3485
|
-
this.processCss(recipe.result, recipe.entry.slot ? "recipes_slots" : "recipes");
|
|
3486
|
-
});
|
|
3487
|
-
}
|
|
3488
|
-
decoder.recipes_base.forEach((baseSet, recipeKey) => {
|
|
3489
|
-
const [baseRecipeName] = recipeKey.split("__");
|
|
3490
|
-
if (baseRecipeName === recipeName) {
|
|
3491
|
-
baseSet.forEach((recipe) => {
|
|
3492
|
-
this.processCss(recipe.result, recipe.slot ? "recipes_slots_base" : "recipes_base");
|
|
3493
|
-
});
|
|
3494
|
-
}
|
|
3495
|
-
});
|
|
3496
|
-
};
|
|
3497
|
-
getLayerCss = (...layers) => {
|
|
3498
|
-
const breakpoints = this.context.conditions.breakpoints;
|
|
3499
|
-
return optimizeCss(
|
|
3500
|
-
layers.map((layer) => {
|
|
3501
|
-
const root = this.context.layers.getLayerRoot(layer);
|
|
3502
|
-
breakpoints.expandScreenAtRule(root);
|
|
3503
|
-
return root.toString();
|
|
3504
|
-
}).join("\n"),
|
|
3505
|
-
{
|
|
3506
|
-
minify: false,
|
|
3507
|
-
browserslist: this.context.browserslist,
|
|
3508
|
-
hooks: this.context.hooks
|
|
3509
|
-
}
|
|
3510
|
-
);
|
|
3511
|
-
};
|
|
3512
|
-
toCss = ({ minify } = {}) => {
|
|
3513
|
-
try {
|
|
3514
|
-
const breakpoints = this.context.conditions.breakpoints;
|
|
3515
|
-
const root = this.context.layers.insert();
|
|
3516
|
-
breakpoints.expandScreenAtRule(root);
|
|
3517
|
-
const plugins = [sortMediaQueries()];
|
|
3518
|
-
if (this.context.polyfill) {
|
|
3519
|
-
plugins.push((0, import_postcss_cascade_layers.default)());
|
|
3520
|
-
}
|
|
3521
|
-
const result = (0, import_postcss6.default)(plugins).process(root);
|
|
3522
|
-
const css = result.toString();
|
|
3523
|
-
return optimizeCss(css, {
|
|
3524
|
-
minify,
|
|
3525
|
-
browserslist: this.context.browserslist,
|
|
3526
|
-
hooks: this.context.hooks
|
|
3527
|
-
});
|
|
3528
|
-
} catch (error) {
|
|
3529
|
-
if (error instanceof import_postcss6.CssSyntaxError) {
|
|
3530
|
-
import_logger4.logger.error("sheet:toCss", error.showSourceCode(true));
|
|
3531
|
-
}
|
|
3532
|
-
throw error;
|
|
3533
|
-
}
|
|
3534
|
-
};
|
|
3535
|
-
};
|
|
3536
|
-
|
|
3537
|
-
// src/utility.ts
|
|
3538
|
-
var import_shared18 = require("@bamboocss/shared");
|
|
3539
|
-
|
|
3540
|
-
// src/color-mix.ts
|
|
3541
|
-
var colorMix = (value, token) => {
|
|
3542
|
-
if (!value || typeof value !== "string") return { invalid: true, value };
|
|
3543
|
-
const [rawColor, rawOpacity] = value.split("/");
|
|
3544
|
-
if (!rawColor || !rawOpacity) {
|
|
3545
|
-
return { invalid: true, value: rawColor };
|
|
3546
|
-
}
|
|
3547
|
-
const colorToken = token(`colors.${rawColor}`);
|
|
3548
|
-
const opacityToken = token.raw(`opacity.${rawOpacity}`)?.value;
|
|
3549
|
-
if (!opacityToken && isNaN(Number(rawOpacity))) {
|
|
3550
|
-
return { invalid: true, value: rawColor };
|
|
3551
|
-
}
|
|
3552
|
-
const percent = opacityToken ? Number(opacityToken) * 100 + "%" : `${rawOpacity}%`;
|
|
3553
|
-
const color = colorToken ?? rawColor;
|
|
3554
|
-
return {
|
|
3555
|
-
invalid: false,
|
|
3556
|
-
color,
|
|
3557
|
-
value: `color-mix(in srgb, ${color} ${percent}, transparent)`
|
|
3558
|
-
};
|
|
3559
|
-
};
|
|
3560
|
-
|
|
3561
|
-
// src/utility.ts
|
|
3562
|
-
var Utility = class {
|
|
3563
|
-
constructor(options) {
|
|
3564
|
-
this.options = options;
|
|
3565
|
-
const { tokens, config = {}, separator, prefix, shorthands, strictTokens } = options;
|
|
3566
|
-
this.tokens = tokens;
|
|
3567
|
-
this.config = this.normalizeConfig(config);
|
|
3568
|
-
if (separator) {
|
|
3569
|
-
this.separator = separator;
|
|
3570
|
-
}
|
|
3571
|
-
if (prefix) {
|
|
3572
|
-
this.prefix = prefix;
|
|
3573
|
-
}
|
|
3574
|
-
if (strictTokens) {
|
|
3575
|
-
this.strictTokens = strictTokens;
|
|
3576
|
-
}
|
|
3577
|
-
if (shorthands) {
|
|
3578
|
-
this.assignShorthands();
|
|
3579
|
-
}
|
|
3580
|
-
this.assignColorPaletteProperty();
|
|
3581
|
-
this.assignProperties();
|
|
3582
|
-
this.assignPropertyTypes();
|
|
3583
|
-
}
|
|
3584
|
-
/**
|
|
3585
|
-
* The token map or dictionary of tokens
|
|
3586
|
-
*/
|
|
3587
|
-
tokens;
|
|
3588
|
-
/**
|
|
3589
|
-
* [cache] The map of property names to their resolved class names
|
|
3590
|
-
*/
|
|
3591
|
-
classNames = /* @__PURE__ */ new Map();
|
|
3592
|
-
/**
|
|
3593
|
-
* [cache] The map of the property to their resolved styless
|
|
3594
|
-
*/
|
|
3595
|
-
styles = /* @__PURE__ */ new Map();
|
|
3596
|
-
/**
|
|
3597
|
-
* Map of shorthand properties to their longhand properties
|
|
3598
|
-
*/
|
|
3599
|
-
shorthands = /* @__PURE__ */ new Map();
|
|
3600
|
-
/**
|
|
3601
|
-
* The map of possible values for each property
|
|
3602
|
-
*/
|
|
3603
|
-
types = /* @__PURE__ */ new Map();
|
|
3604
|
-
/**
|
|
3605
|
-
* The map of the property keys
|
|
3606
|
-
*/
|
|
3607
|
-
propertyTypeKeys = /* @__PURE__ */ new Map();
|
|
3608
|
-
/**
|
|
3609
|
-
* The utility config
|
|
3610
|
-
*/
|
|
3611
|
-
config = {};
|
|
3612
|
-
/**
|
|
3613
|
-
* The map of property names to their transform functions
|
|
3614
|
-
*/
|
|
3615
|
-
transforms = /* @__PURE__ */ new Map();
|
|
3616
|
-
/**
|
|
3617
|
-
* The map of property names to their config
|
|
3618
|
-
*/
|
|
3619
|
-
configs = /* @__PURE__ */ new Map();
|
|
3620
|
-
/**
|
|
3621
|
-
* The map of deprecated properties
|
|
3622
|
-
*/
|
|
3623
|
-
deprecated = /* @__PURE__ */ new Set();
|
|
3624
|
-
separator = "_";
|
|
3625
|
-
prefix = "";
|
|
3626
|
-
strictTokens = false;
|
|
3627
|
-
defaultHashFn = import_shared18.toHash;
|
|
3628
|
-
toHash = (path, hashFn) => hashFn(path.join(":"));
|
|
3629
|
-
normalizeConfig(config) {
|
|
3630
|
-
return Object.fromEntries(
|
|
3631
|
-
Object.entries(config).map(([property, propertyConfig]) => {
|
|
3632
|
-
return [property, this.normalize(propertyConfig)];
|
|
3633
|
-
})
|
|
3634
|
-
);
|
|
3635
|
-
}
|
|
3636
|
-
assignDeprecated = (property, config) => {
|
|
3637
|
-
if (!config.deprecated) return;
|
|
3638
|
-
this.deprecated.add(property);
|
|
3639
|
-
if ((0, import_shared18.isString)(config.shorthand)) this.deprecated.add(config.shorthand);
|
|
3640
|
-
if (Array.isArray(config.shorthand)) {
|
|
3641
|
-
config.shorthand.forEach((shorthand) => this.deprecated.add(shorthand));
|
|
3642
|
-
}
|
|
3643
|
-
};
|
|
3644
|
-
register = (property, config) => {
|
|
3645
|
-
this.config[property] = this.normalize(config);
|
|
3646
|
-
this.assignProperty(property, config);
|
|
3647
|
-
this.assignPropertyType(property, config);
|
|
3648
|
-
};
|
|
3649
|
-
assignShorthands = () => {
|
|
3650
|
-
for (const [property, config] of Object.entries(this.config)) {
|
|
3651
|
-
const { shorthand } = config ?? {};
|
|
3652
|
-
if (!shorthand) continue;
|
|
3653
|
-
const values = Array.isArray(shorthand) ? shorthand : [shorthand];
|
|
3654
|
-
values.forEach((shorthandName) => {
|
|
3655
|
-
this.shorthands.set(shorthandName, property);
|
|
3656
|
-
});
|
|
3657
|
-
}
|
|
3658
|
-
};
|
|
3659
|
-
assignColorPaletteProperty = () => {
|
|
3660
|
-
if (!this.tokens.view.colorPalettes.size) return;
|
|
3661
|
-
const values = (0, import_shared18.mapToJson)(this.tokens.view.colorPalettes);
|
|
3662
|
-
this.config.colorPalette = {
|
|
3663
|
-
values: Object.keys(values),
|
|
3664
|
-
transform(value) {
|
|
3665
|
-
return values[value];
|
|
3666
|
-
}
|
|
3667
|
-
};
|
|
3668
|
-
};
|
|
3669
|
-
resolveShorthand = (prop) => {
|
|
3670
|
-
return this.shorthands.get(prop) ?? prop;
|
|
3671
|
-
};
|
|
3672
|
-
get hasShorthand() {
|
|
3673
|
-
return this.shorthands.size > 0;
|
|
3674
|
-
}
|
|
3675
|
-
get isEmpty() {
|
|
3676
|
-
return Object.keys(this.config).length === 0;
|
|
3677
|
-
}
|
|
3678
|
-
entries = () => {
|
|
3679
|
-
const value = Object.entries(this.config).filter(([, value2]) => !!value2?.className).map(([key, value2]) => [key, value2.className]);
|
|
3680
|
-
return value;
|
|
3681
|
-
};
|
|
3682
|
-
getPropKey = (prop, value) => {
|
|
3683
|
-
return `(${prop} = ${value})`;
|
|
3684
|
-
};
|
|
3685
|
-
hash = (prop, value) => {
|
|
3686
|
-
return `${prop}${this.separator}${value}`;
|
|
3687
|
-
};
|
|
3688
|
-
/**
|
|
3689
|
-
* Get all the possible values for the defined property
|
|
3690
|
-
*/
|
|
3691
|
-
getPropertyValues = (config, resolveFn) => {
|
|
3692
|
-
const { values } = config;
|
|
3693
|
-
const fn = (key) => {
|
|
3694
|
-
const categoryValues = this.getTokenCategoryValues(key);
|
|
3695
|
-
if (!categoryValues) return;
|
|
3696
|
-
const prop = resolveFn?.(key);
|
|
3697
|
-
if (!prop) return;
|
|
3698
|
-
return { [prop]: categoryValues };
|
|
3699
|
-
};
|
|
3700
|
-
if ((0, import_shared18.isString)(values)) {
|
|
3701
|
-
return fn?.(values) ?? this.tokens.view.getCategoryValues(values) ?? {};
|
|
3702
|
-
}
|
|
3703
|
-
if (Array.isArray(values)) {
|
|
3704
|
-
return values.reduce((result, value) => {
|
|
3705
|
-
result[value] = value;
|
|
3706
|
-
return result;
|
|
3707
|
-
}, {});
|
|
3708
|
-
}
|
|
3709
|
-
if ((0, import_shared18.isFunction)(values)) {
|
|
3710
|
-
return values(resolveFn ? fn : this.getTokenCategoryValues.bind(this));
|
|
3711
|
-
}
|
|
3712
|
-
return values;
|
|
3713
|
-
};
|
|
3714
|
-
getPropertyRawValue(config, value) {
|
|
3715
|
-
const { values } = config;
|
|
3716
|
-
if (!values) return value;
|
|
3717
|
-
if ((0, import_shared18.isString)(values)) {
|
|
3718
|
-
return this.tokens.view.valuesByCategory.get(values)?.get(String(value)) || value;
|
|
3719
|
-
}
|
|
3720
|
-
if (Array.isArray(values)) {
|
|
3721
|
-
return value;
|
|
3722
|
-
}
|
|
3723
|
-
if ((0, import_shared18.isFunction)(values)) {
|
|
3724
|
-
return values(this.getTokenCategoryValues.bind(this))[value] || value;
|
|
3725
|
-
}
|
|
3726
|
-
if (values.type) {
|
|
3727
|
-
return value;
|
|
3728
|
-
}
|
|
3729
|
-
return values[value] || value;
|
|
3730
|
-
}
|
|
3731
|
-
getToken = (path) => {
|
|
3732
|
-
return this.tokens.view.getVar(path);
|
|
3733
|
-
};
|
|
3734
|
-
getTokenCategoryValues = (category) => {
|
|
3735
|
-
return this.tokens.view.getCategoryValues(category);
|
|
3736
|
-
};
|
|
3737
|
-
/**
|
|
3738
|
-
* Normalize the property config
|
|
3739
|
-
*/
|
|
3740
|
-
normalize = (propertyConfig) => {
|
|
3741
|
-
const config = { ...propertyConfig };
|
|
3742
|
-
if (config.values === "keyframes") {
|
|
3743
|
-
config.values = Object.keys(this.options.keyframes ?? {});
|
|
3744
|
-
}
|
|
3745
|
-
if (config.shorthand && !config.className) {
|
|
3746
|
-
config.className = Array.isArray(config.shorthand) ? config.shorthand[0] : config.shorthand;
|
|
3747
|
-
}
|
|
3748
|
-
return config;
|
|
3749
|
-
};
|
|
3750
|
-
assignProperty = (property, config) => {
|
|
3751
|
-
this.setTransform(property, config?.transform);
|
|
3752
|
-
this.assignDeprecated(property, config);
|
|
3753
|
-
if (!config) return;
|
|
3754
|
-
this.configs.set(property, config);
|
|
3755
|
-
};
|
|
3756
|
-
assignProperties = () => {
|
|
3757
|
-
for (const [property, propertyConfig] of Object.entries(this.config)) {
|
|
3758
|
-
if (!propertyConfig) continue;
|
|
3759
|
-
this.assignProperty(property, propertyConfig);
|
|
3760
|
-
}
|
|
3761
|
-
};
|
|
3762
|
-
assignPropertiesValues = () => {
|
|
3763
|
-
for (const [property, propertyConfig] of Object.entries(this.config)) {
|
|
3764
|
-
if (!propertyConfig) continue;
|
|
3765
|
-
this.assignPropertyValues(property, propertyConfig);
|
|
3766
|
-
}
|
|
3767
|
-
return this;
|
|
3768
|
-
};
|
|
3769
|
-
assignPropertyValues = (property, config) => {
|
|
3770
|
-
const values = this.getPropertyValues(config);
|
|
3771
|
-
if (!values) return;
|
|
3772
|
-
for (const [alias, raw] of Object.entries(values)) {
|
|
3773
|
-
const propKey = this.getPropKey(property, alias);
|
|
3774
|
-
this.setStyles(property, raw, alias, propKey);
|
|
3775
|
-
this.getOrCreateClassName(property, alias);
|
|
3776
|
-
}
|
|
3777
|
-
};
|
|
3778
|
-
getPropertyKeys = (prop) => {
|
|
3779
|
-
const propConfig = this.config[prop];
|
|
3780
|
-
if (!propConfig) return [];
|
|
3781
|
-
const values = this.getPropertyValues(propConfig);
|
|
3782
|
-
if (!values) return [];
|
|
3783
|
-
return Object.keys(values);
|
|
3784
|
-
};
|
|
3785
|
-
getPropertyTypeKeys = (property) => {
|
|
3786
|
-
const keys2 = this.propertyTypeKeys.get(property);
|
|
3787
|
-
return keys2 ? Array.from(keys2) : [];
|
|
3788
|
-
};
|
|
3789
|
-
assignPropertyType = (property, config) => {
|
|
3790
|
-
if (!config) return;
|
|
3791
|
-
const values = this.getPropertyValues(config, (key) => `type:Tokens["${key}"]`);
|
|
3792
|
-
if (typeof values === "object" && values.type) {
|
|
3793
|
-
this.types.set(property, /* @__PURE__ */ new Set([`type:${values.type}`]));
|
|
3794
|
-
return;
|
|
3795
|
-
}
|
|
3796
|
-
if (values) {
|
|
3797
|
-
const keys2 = new Set(Object.keys(values));
|
|
3798
|
-
this.types.set(property, keys2);
|
|
3799
|
-
this.propertyTypeKeys.set(property, keys2);
|
|
3800
|
-
}
|
|
3801
|
-
const set = this.types.get(property) ?? /* @__PURE__ */ new Set();
|
|
3802
|
-
if (!this.strictTokens && config.property) {
|
|
3803
|
-
this.types.set(property, set.add(`CssProperties["${config.property}"]`));
|
|
3804
|
-
}
|
|
3805
|
-
};
|
|
3806
|
-
assignPropertyTypes = () => {
|
|
3807
|
-
for (const [property, propertyConfig] of Object.entries(this.config)) {
|
|
3808
|
-
if (!propertyConfig) continue;
|
|
3809
|
-
this.assignPropertyType(property, propertyConfig);
|
|
3810
|
-
}
|
|
3811
|
-
};
|
|
3812
|
-
addPropertyType = (property, type) => {
|
|
3813
|
-
const set = this.types.get(property) ?? /* @__PURE__ */ new Set();
|
|
3814
|
-
this.types.set(property, /* @__PURE__ */ new Set([...set, ...type]));
|
|
3815
|
-
};
|
|
3816
|
-
/**
|
|
3817
|
-
* Returns the Typescript type for the define properties
|
|
3818
|
-
*/
|
|
3819
|
-
getTypes = () => {
|
|
3820
|
-
const map = /* @__PURE__ */ new Map();
|
|
3821
|
-
for (const [prop, tokens] of this.types.entries()) {
|
|
3822
|
-
if (tokens.size === 0) {
|
|
3823
|
-
continue;
|
|
3824
|
-
}
|
|
3825
|
-
const typeValues = Array.from(tokens).map((key) => {
|
|
3826
|
-
if (key.startsWith("CssProperties")) return key;
|
|
3827
|
-
if (key.startsWith("type:")) return key.replace("type:", "");
|
|
3828
|
-
return JSON.stringify(key);
|
|
3829
|
-
});
|
|
3830
|
-
map.set(prop, typeValues);
|
|
3831
|
-
}
|
|
3832
|
-
return map;
|
|
3833
|
-
};
|
|
3834
|
-
defaultTransform = (0, import_shared18.memo)((value, prop) => {
|
|
3835
|
-
const isCssVar = prop.startsWith("--");
|
|
3836
|
-
if (isCssVar) {
|
|
3837
|
-
const tokenValue = this.tokens.view.getVar(value);
|
|
3838
|
-
value = typeof tokenValue === "string" ? tokenValue : value;
|
|
3839
|
-
}
|
|
3840
|
-
return { [prop]: value };
|
|
3841
|
-
});
|
|
3842
|
-
setTransform = (property, transform) => {
|
|
3843
|
-
const defaultTransform = (value) => this.defaultTransform(value, property);
|
|
3844
|
-
const transformFn = transform ?? defaultTransform;
|
|
3845
|
-
this.transforms.set(property, transformFn);
|
|
3846
|
-
return this;
|
|
3847
|
-
};
|
|
3848
|
-
getTokenFn = () => {
|
|
3849
|
-
return Object.assign(this.getToken.bind(this), {
|
|
3850
|
-
raw: (path) => this.tokens.getByName(path)
|
|
3851
|
-
});
|
|
3852
|
-
};
|
|
3853
|
-
resolveColorMix = (value) => {
|
|
3854
|
-
const token = this.getTokenFn();
|
|
3855
|
-
return colorMix(value, token);
|
|
3856
|
-
};
|
|
3857
|
-
getTransformArgs = (raw) => {
|
|
3858
|
-
return {
|
|
3859
|
-
token: this.getTokenFn(),
|
|
3860
|
-
raw,
|
|
3861
|
-
utils: {
|
|
3862
|
-
colorMix: this.resolveColorMix.bind(this)
|
|
3863
|
-
}
|
|
3864
|
-
};
|
|
3865
|
-
};
|
|
3866
|
-
setStyles = (property, raw, alias, propKey) => {
|
|
3867
|
-
propKey = propKey ?? this.getPropKey(property, raw);
|
|
3868
|
-
const defaultTransform = (value) => this.defaultTransform(value, property);
|
|
3869
|
-
const getStyles = this.transforms.get(property) ?? defaultTransform;
|
|
3870
|
-
const styles = getStyles(raw, this.getTransformArgs(alias));
|
|
3871
|
-
this.styles.set(propKey, styles ?? {});
|
|
3872
|
-
return this;
|
|
3873
|
-
};
|
|
3874
|
-
formatClassName = (className) => {
|
|
3875
|
-
return [this.prefix, className].filter(Boolean).join("-");
|
|
3876
|
-
};
|
|
3877
|
-
/**
|
|
3878
|
-
* Returns the resolved className for a given property and value
|
|
3879
|
-
*/
|
|
3880
|
-
getClassName = (property, raw) => {
|
|
3881
|
-
const config = this.configs.get(property);
|
|
3882
|
-
if (!config || !config.className) {
|
|
3883
|
-
return this.hash((0, import_shared18.hypenateProperty)(property), raw);
|
|
3884
|
-
}
|
|
3885
|
-
return this.hash(config.className, raw);
|
|
3886
|
-
};
|
|
3887
|
-
getOrCreateClassName = (property, raw) => {
|
|
3888
|
-
const propKey = this.getPropKey(property, raw);
|
|
3889
|
-
let className = this.classNames.get(propKey);
|
|
3890
|
-
if (!className) {
|
|
3891
|
-
className = this.getClassName(property, raw);
|
|
3892
|
-
this.classNames.set(propKey, className);
|
|
3893
|
-
}
|
|
3894
|
-
return className;
|
|
3895
|
-
};
|
|
3896
|
-
/**
|
|
3897
|
-
* Whether a given property exists in the config
|
|
3898
|
-
*/
|
|
3899
|
-
has = (prop) => {
|
|
3900
|
-
return this.configs.has(prop);
|
|
3901
|
-
};
|
|
3902
|
-
/**
|
|
3903
|
-
* Get or create the resolved styles for a given property and value
|
|
3904
|
-
*/
|
|
3905
|
-
getOrCreateStyle = (prop, value) => {
|
|
3906
|
-
const propKey = this.getPropKey(prop, value);
|
|
3907
|
-
const styles = this.styles.get(propKey);
|
|
3908
|
-
if (styles) return styles;
|
|
3909
|
-
const config = this.configs.get(prop);
|
|
3910
|
-
const raw = config ? this.getPropertyRawValue(config, value) : value;
|
|
3911
|
-
this.setStyles(prop, raw, value, propKey);
|
|
3912
|
-
return this.styles.get(propKey);
|
|
3913
|
-
};
|
|
3914
|
-
/**
|
|
3915
|
-
* Returns the resolved className and styles for a given property and value
|
|
3916
|
-
*/
|
|
3917
|
-
transform = (prop, value) => {
|
|
3918
|
-
if (value == null) {
|
|
3919
|
-
return { className: "", styles: {} };
|
|
3920
|
-
}
|
|
3921
|
-
const key = this.resolveShorthand(prop);
|
|
3922
|
-
let styleValue = (0, import_shared18.getArbitraryValue)(value);
|
|
3923
|
-
if ((0, import_shared18.isString)(styleValue)) {
|
|
3924
|
-
styleValue = this.tokens.expandReferenceInValue(styleValue);
|
|
3925
|
-
}
|
|
3926
|
-
return (0, import_shared18.compact)({
|
|
3927
|
-
layer: this.configs.get(key)?.layer,
|
|
3928
|
-
className: this.getOrCreateClassName(key, (0, import_shared18.withoutSpace)(value)),
|
|
3929
|
-
styles: this.getOrCreateStyle(key, styleValue)
|
|
3930
|
-
});
|
|
3931
|
-
};
|
|
3932
|
-
/**
|
|
3933
|
-
* All keys including shorthand keys
|
|
3934
|
-
*/
|
|
3935
|
-
keys = () => {
|
|
3936
|
-
const shorthands = Array.from(this.shorthands.keys());
|
|
3937
|
-
const properties = Object.keys(this.config);
|
|
3938
|
-
return [...shorthands, ...properties];
|
|
3939
|
-
};
|
|
3940
|
-
/**
|
|
3941
|
-
* Returns a map of the property keys and their shorthands
|
|
3942
|
-
*/
|
|
3943
|
-
getPropShorthandsMap = () => {
|
|
3944
|
-
const shorthandsByProp = /* @__PURE__ */ new Map();
|
|
3945
|
-
this.shorthands.forEach((prop, shorthand) => {
|
|
3946
|
-
const list = shorthandsByProp.get(prop) ?? [];
|
|
3947
|
-
list.push(shorthand);
|
|
3948
|
-
shorthandsByProp.set(prop, list);
|
|
3949
|
-
});
|
|
3950
|
-
return shorthandsByProp;
|
|
3951
|
-
};
|
|
3952
|
-
/**
|
|
3953
|
-
* Returns the shorthands for a given property
|
|
3954
|
-
*/
|
|
3955
|
-
getPropShorthands = (prop) => {
|
|
3956
|
-
return this.getPropShorthandsMap().get(prop) ?? [];
|
|
3957
|
-
};
|
|
3958
|
-
/**
|
|
3959
|
-
* Whether a given property is deprecated
|
|
3960
|
-
*/
|
|
3961
|
-
isDeprecated = (prop) => {
|
|
3962
|
-
return this.deprecated.has(prop);
|
|
3963
|
-
};
|
|
3964
|
-
/**
|
|
3965
|
-
* Returns the token type for a given property
|
|
3966
|
-
*/
|
|
3967
|
-
getTokenType = (prop) => {
|
|
3968
|
-
const set = this.types.get(prop);
|
|
3969
|
-
if (!set) return;
|
|
3970
|
-
for (const type of set) {
|
|
3971
|
-
const match3 = type.match(TOKEN_TYPE_PATTERN);
|
|
3972
|
-
if (match3) return match3[1];
|
|
3973
|
-
}
|
|
3974
|
-
};
|
|
3975
|
-
};
|
|
3976
|
-
var TOKEN_TYPE_PATTERN = /type:Tokens\["([^"]+)"\]/;
|
|
3977
|
-
|
|
3978
|
-
// src/context.ts
|
|
3979
|
-
var defaults = (config) => ({
|
|
3980
|
-
cssVarRoot: ":where(:root, :host)",
|
|
3981
|
-
jsxFactory: "styled",
|
|
3982
|
-
jsxStyleProps: "all",
|
|
3983
|
-
outExtension: "mjs",
|
|
3984
|
-
shorthands: true,
|
|
3985
|
-
syntax: "object-literal",
|
|
3986
|
-
...config,
|
|
3987
|
-
layers: {
|
|
3988
|
-
reset: "reset",
|
|
3989
|
-
base: "base",
|
|
3990
|
-
tokens: "tokens",
|
|
3991
|
-
recipes: "recipes",
|
|
3992
|
-
utilities: "utilities",
|
|
3993
|
-
...config.layers
|
|
3994
|
-
}
|
|
3995
|
-
});
|
|
3996
|
-
var Context = class {
|
|
3997
|
-
constructor(conf) {
|
|
3998
|
-
this.conf = conf;
|
|
3999
|
-
const config = defaults(conf.config);
|
|
4000
|
-
const theme = config.theme ?? {};
|
|
4001
|
-
conf.config = config;
|
|
4002
|
-
this.tokens = this.createTokenDictionary(theme, config.themes);
|
|
4003
|
-
this.hooks["tokens:created"]?.({
|
|
4004
|
-
configure: (opts) => {
|
|
4005
|
-
if (opts.formatTokenName) {
|
|
4006
|
-
this.tokens.formatTokenName = opts.formatTokenName;
|
|
4007
|
-
}
|
|
4008
|
-
if (opts.formatCssVar) {
|
|
4009
|
-
this.tokens.formatCssVar = opts.formatCssVar;
|
|
4010
|
-
}
|
|
4011
|
-
}
|
|
4012
|
-
});
|
|
4013
|
-
this.tokens.init();
|
|
4014
|
-
this.utility = this.createUtility(config);
|
|
4015
|
-
this.hooks["utility:created"]?.({
|
|
4016
|
-
configure: (opts) => {
|
|
4017
|
-
if (opts.toHash) {
|
|
4018
|
-
this.utility.toHash = opts.toHash;
|
|
4019
|
-
}
|
|
4020
|
-
}
|
|
4021
|
-
});
|
|
4022
|
-
this.conditions = this.createConditions(config);
|
|
4023
|
-
this.patterns = new Patterns({
|
|
4024
|
-
config,
|
|
4025
|
-
tokens: this.tokens,
|
|
4026
|
-
utility: this.utility,
|
|
4027
|
-
helpers: import_shared19.patternFns
|
|
4028
|
-
});
|
|
4029
|
-
this.studio = { outdir: `${config.outdir}-studio`, ...conf.config.studio };
|
|
4030
|
-
this.setupProperties();
|
|
4031
|
-
this.recipes = this.createRecipes(theme);
|
|
4032
|
-
this.encoder = new StyleEncoder({
|
|
4033
|
-
utility: this.utility,
|
|
4034
|
-
recipes: this.recipes,
|
|
4035
|
-
conditions: this.conditions,
|
|
4036
|
-
patterns: this.patterns,
|
|
4037
|
-
isTemplateLiteralSyntax: this.isTemplateLiteralSyntax,
|
|
4038
|
-
isValidProperty: this.isValidProperty
|
|
4039
|
-
});
|
|
4040
|
-
this.decoder = new StyleDecoder({
|
|
4041
|
-
conditions: this.conditions,
|
|
4042
|
-
utility: this.utility,
|
|
4043
|
-
recipes: this.recipes,
|
|
4044
|
-
hash: this.hash
|
|
4045
|
-
});
|
|
4046
|
-
this.setupCompositions(theme);
|
|
4047
|
-
this.registerAnimationName(theme);
|
|
4048
|
-
this.registerFontFamily(config.globalFontface);
|
|
4049
|
-
this.recipes.save(this.baseSheetContext);
|
|
4050
|
-
this.staticCss = new StaticCss({
|
|
4051
|
-
config,
|
|
4052
|
-
utility: this.utility,
|
|
4053
|
-
patterns: this.patterns,
|
|
4054
|
-
recipes: this.recipes,
|
|
4055
|
-
createSheet: this.createSheet,
|
|
4056
|
-
encoder: this.encoder,
|
|
4057
|
-
decoder: this.decoder
|
|
4058
|
-
});
|
|
4059
|
-
this.jsx = new JsxEngine({
|
|
4060
|
-
patterns: this.patterns,
|
|
4061
|
-
recipes: this.recipes,
|
|
4062
|
-
config
|
|
4063
|
-
});
|
|
4064
|
-
this.imports = new ImportMap({
|
|
4065
|
-
jsx: this.jsx,
|
|
4066
|
-
conf: this.conf,
|
|
4067
|
-
config: this.config,
|
|
4068
|
-
patterns: this.patterns,
|
|
4069
|
-
recipes: this.recipes,
|
|
4070
|
-
isValidProperty: this.isValidProperty
|
|
4071
|
-
});
|
|
4072
|
-
this.paths = new PathEngine({
|
|
4073
|
-
config: this.config
|
|
4074
|
-
});
|
|
4075
|
-
this.file = new FileEngine({
|
|
4076
|
-
config: this.config
|
|
4077
|
-
});
|
|
4078
|
-
this.globalVars = new GlobalVars({
|
|
4079
|
-
globalVars: this.config.globalVars,
|
|
4080
|
-
cssVarRoot: this.config.cssVarRoot
|
|
4081
|
-
});
|
|
4082
|
-
this.globalFontface = new GlobalFontface({
|
|
4083
|
-
globalFontface: this.config.globalFontface
|
|
4084
|
-
});
|
|
4085
|
-
this.globalPositionTry = new GlobalPositionTry({
|
|
4086
|
-
globalPositionTry: this.config.globalPositionTry
|
|
4087
|
-
});
|
|
4088
|
-
this.messages = getMessages({
|
|
4089
|
-
jsx: this.jsx,
|
|
4090
|
-
config: this.config,
|
|
4091
|
-
tokens: this.tokens,
|
|
4092
|
-
recipes: this.recipes,
|
|
4093
|
-
patterns: this.patterns,
|
|
4094
|
-
isTemplateLiteralSyntax: this.isTemplateLiteralSyntax
|
|
4095
|
-
});
|
|
4096
|
-
this.parserOptions = {
|
|
4097
|
-
hash: this.hash,
|
|
4098
|
-
compilerOptions: this.conf.tsconfig?.compilerOptions ?? {},
|
|
4099
|
-
recipes: this.recipes,
|
|
4100
|
-
patterns: this.patterns,
|
|
4101
|
-
jsx: this.jsx,
|
|
4102
|
-
config: this.config,
|
|
4103
|
-
tokens: this.tokens,
|
|
4104
|
-
conditions: this.conditions,
|
|
4105
|
-
utility: this.utility,
|
|
4106
|
-
encoder: this.encoder,
|
|
4107
|
-
tsOptions: this.conf.tsOptions,
|
|
4108
|
-
join: (...paths) => paths.join("/"),
|
|
4109
|
-
imports: this.imports
|
|
4110
|
-
};
|
|
4111
|
-
this.hooksApi = new HooksApi(this);
|
|
4112
|
-
this.hooks["context:created"]?.({ ctx: this.hooksApi, logger: import_logger5.logger });
|
|
4113
|
-
}
|
|
4114
|
-
studio;
|
|
4115
|
-
// Engines
|
|
4116
|
-
tokens;
|
|
4117
|
-
utility;
|
|
4118
|
-
recipes;
|
|
4119
|
-
conditions;
|
|
4120
|
-
patterns;
|
|
4121
|
-
staticCss;
|
|
4122
|
-
jsx;
|
|
4123
|
-
imports;
|
|
4124
|
-
paths;
|
|
4125
|
-
file;
|
|
4126
|
-
globalVars;
|
|
4127
|
-
globalFontface;
|
|
4128
|
-
globalPositionTry;
|
|
4129
|
-
encoder;
|
|
4130
|
-
decoder;
|
|
4131
|
-
hooksApi;
|
|
4132
|
-
// Props
|
|
4133
|
-
properties;
|
|
4134
|
-
isValidProperty;
|
|
4135
|
-
messages;
|
|
4136
|
-
parserOptions;
|
|
4137
|
-
get config() {
|
|
4138
|
-
return this.conf.config;
|
|
4139
|
-
}
|
|
4140
|
-
get hooks() {
|
|
4141
|
-
return this.conf.hooks ?? {};
|
|
4142
|
-
}
|
|
4143
|
-
get isTemplateLiteralSyntax() {
|
|
4144
|
-
return this.config.syntax === "template-literal";
|
|
4145
|
-
}
|
|
4146
|
-
get hash() {
|
|
4147
|
-
return {
|
|
4148
|
-
tokens: (0, import_shared19.isBoolean)(this.config.hash) ? this.config.hash : this.config.hash?.cssVar,
|
|
4149
|
-
className: (0, import_shared19.isBoolean)(this.config.hash) ? this.config.hash : this.config.hash?.className
|
|
4150
|
-
};
|
|
4151
|
-
}
|
|
4152
|
-
get prefix() {
|
|
4153
|
-
return {
|
|
4154
|
-
tokens: (0, import_shared19.isString)(this.config.prefix) ? this.config.prefix : this.config.prefix?.cssVar,
|
|
4155
|
-
className: (0, import_shared19.isString)(this.config.prefix) ? this.config.prefix : this.config.prefix?.className
|
|
4156
|
-
};
|
|
4157
|
-
}
|
|
4158
|
-
createTokenDictionary = (theme, themeVariants) => {
|
|
4159
|
-
return new import_token_dictionary.TokenDictionary({
|
|
4160
|
-
breakpoints: theme.breakpoints,
|
|
4161
|
-
tokens: theme.tokens,
|
|
4162
|
-
semanticTokens: theme.semanticTokens,
|
|
4163
|
-
themes: themeVariants,
|
|
4164
|
-
prefix: this.prefix.tokens,
|
|
4165
|
-
hash: this.hash.tokens,
|
|
4166
|
-
colorPalette: theme.colorPalette
|
|
4167
|
-
});
|
|
4168
|
-
};
|
|
4169
|
-
createUtility = (config) => {
|
|
4170
|
-
return new Utility({
|
|
4171
|
-
prefix: this.prefix.className,
|
|
4172
|
-
tokens: this.tokens,
|
|
4173
|
-
config: this.isTemplateLiteralSyntax ? {} : Object.assign({}, config.utilities),
|
|
4174
|
-
separator: config.separator,
|
|
4175
|
-
shorthands: config.shorthands,
|
|
4176
|
-
strictTokens: config.strictTokens,
|
|
4177
|
-
keyframes: config.theme?.keyframes
|
|
4178
|
-
});
|
|
4179
|
-
};
|
|
4180
|
-
createConditions = (config) => {
|
|
4181
|
-
return new Conditions({
|
|
4182
|
-
conditions: config.conditions,
|
|
4183
|
-
containerNames: config.theme?.containerNames,
|
|
4184
|
-
containerSizes: config.theme?.containerSizes,
|
|
4185
|
-
breakpoints: config.theme?.breakpoints,
|
|
4186
|
-
themes: config.themes
|
|
4187
|
-
});
|
|
4188
|
-
};
|
|
4189
|
-
createLayers = (layers) => {
|
|
4190
|
-
return new Layers(layers);
|
|
4191
|
-
};
|
|
4192
|
-
setupCompositions = (theme) => {
|
|
4193
|
-
const { textStyles, layerStyles, animationStyles } = theme;
|
|
4194
|
-
const compositions = (0, import_shared19.compact)({
|
|
4195
|
-
textStyle: textStyles,
|
|
4196
|
-
layerStyle: layerStyles,
|
|
4197
|
-
animationStyle: animationStyles
|
|
4198
|
-
});
|
|
4199
|
-
const stylesheetCtx = {
|
|
4200
|
-
...this.baseSheetContext,
|
|
4201
|
-
layers: this.createLayers(this.config.layers)
|
|
4202
|
-
};
|
|
4203
|
-
for (const [key, values] of Object.entries(compositions)) {
|
|
4204
|
-
this.properties.add(key);
|
|
4205
|
-
const flatValues = (0, import_shared19.flatten)(values ?? {});
|
|
4206
|
-
const config = {
|
|
4207
|
-
layer: "compositions",
|
|
4208
|
-
className: key,
|
|
4209
|
-
values: Object.keys(flatValues),
|
|
4210
|
-
transform: (value) => {
|
|
4211
|
-
return transformStyles(stylesheetCtx, flatValues[value], key + "." + value);
|
|
4212
|
-
}
|
|
4213
|
-
};
|
|
4214
|
-
this.utility.register(key, config);
|
|
4215
|
-
}
|
|
4216
|
-
};
|
|
4217
|
-
registerAnimationName = (theme) => {
|
|
4218
|
-
this.utility.addPropertyType("animationName", Object.keys(theme.keyframes ?? {}));
|
|
4219
|
-
};
|
|
4220
|
-
registerFontFamily = (fontFaces) => {
|
|
4221
|
-
this.utility.addPropertyType("fontFamily", Object.keys(fontFaces ?? {}));
|
|
4222
|
-
};
|
|
4223
|
-
setupProperties = () => {
|
|
4224
|
-
this.properties = /* @__PURE__ */ new Set(["css", ...this.utility.keys(), ...this.conditions.keys()]);
|
|
4225
|
-
this.isValidProperty = (0, import_shared19.memo)((key) => this.properties.has(key) || (0, import_is_valid_prop.isCssProperty)(key));
|
|
4226
|
-
};
|
|
4227
|
-
get baseSheetContext() {
|
|
4228
|
-
return {
|
|
4229
|
-
conditions: this.conditions,
|
|
4230
|
-
utility: this.utility,
|
|
4231
|
-
hash: this.hash.className,
|
|
4232
|
-
encoder: this.encoder,
|
|
4233
|
-
decoder: this.decoder,
|
|
4234
|
-
hooks: this.hooks,
|
|
4235
|
-
isValidProperty: this.isValidProperty,
|
|
4236
|
-
browserslist: this.config.browserslist,
|
|
4237
|
-
polyfill: this.config.polyfill,
|
|
4238
|
-
cssVarRoot: this.config.cssVarRoot,
|
|
4239
|
-
helpers: import_shared19.patternFns,
|
|
4240
|
-
globalVars: this.globalVars,
|
|
4241
|
-
globalFontface: this.globalFontface,
|
|
4242
|
-
globalPositionTry: this.globalPositionTry
|
|
4243
|
-
};
|
|
4244
|
-
}
|
|
4245
|
-
createSheet = () => {
|
|
4246
|
-
return new Stylesheet({
|
|
4247
|
-
...this.baseSheetContext,
|
|
4248
|
-
layers: this.createLayers(this.config.layers)
|
|
4249
|
-
});
|
|
4250
|
-
};
|
|
4251
|
-
createRecipes = (theme) => {
|
|
4252
|
-
const recipeConfigs = Object.assign({}, theme.recipes ?? {}, theme.slotRecipes ?? {});
|
|
4253
|
-
return new Recipes(recipeConfigs);
|
|
4254
|
-
};
|
|
4255
|
-
isValidLayerParams = (params) => {
|
|
4256
|
-
const names = new Set(params.split(",").map((name) => name.trim()));
|
|
4257
|
-
return names.size >= 5 && Object.values(this.config.layers).every((name) => names.has(name));
|
|
4258
|
-
};
|
|
4259
|
-
};
|
|
4260
|
-
|
|
4261
|
-
// src/selector.ts
|
|
4262
|
-
var import_postcss_selector_parser = __toESM(require("postcss-selector-parser"));
|
|
4263
|
-
var import_ts_pattern2 = require("ts-pattern");
|
|
4264
|
-
var parentNestingRegex = /\s&/g;
|
|
4265
|
-
function extractParentSelectors(selector) {
|
|
4266
|
-
const result = /* @__PURE__ */ new Set();
|
|
4267
|
-
(0, import_postcss_selector_parser.default)((selectors) => {
|
|
4268
|
-
selectors.each((selector2) => {
|
|
4269
|
-
const condition = parseCondition(selector2.toString());
|
|
4270
|
-
(0, import_ts_pattern2.match)(condition).with({ type: "parent-nesting" }, () => {
|
|
4271
|
-
result.add(selector2.toString().replace(parentNestingRegex, "").trim());
|
|
4272
|
-
}).otherwise(() => {
|
|
4273
|
-
});
|
|
4274
|
-
});
|
|
4275
|
-
}).processSync(selector);
|
|
4276
|
-
const finalized = Array.from(result).join(", ").trim();
|
|
4277
|
-
return result.size > 1 ? `:where(${finalized})` : finalized;
|
|
4278
|
-
}
|
|
4279
|
-
function extractTrailingPseudos(selector) {
|
|
4280
|
-
const ast = (0, import_postcss_selector_parser.default)((selectors) => selectors).astSync(selector);
|
|
4281
|
-
const matrix = [];
|
|
4282
|
-
for (const [i, sel] of ast.nodes.entries()) {
|
|
4283
|
-
for (const [j, child] of [...sel.nodes].reverse().entries()) {
|
|
4284
|
-
if (child.type !== "pseudo" || !child.value.startsWith("::")) {
|
|
4285
|
-
break;
|
|
4286
|
-
}
|
|
4287
|
-
matrix[j] = matrix[j] || [];
|
|
4288
|
-
matrix[j][i] = child;
|
|
4289
|
-
}
|
|
4290
|
-
}
|
|
4291
|
-
const trailingPseudos = import_postcss_selector_parser.default.selector({ value: "" });
|
|
4292
|
-
for (const pseudos of matrix) {
|
|
4293
|
-
if (!pseudos) continue;
|
|
4294
|
-
const values = new Set(pseudos.map((p) => p.value));
|
|
4295
|
-
if (values.size > 1) break;
|
|
4296
|
-
pseudos.forEach((pseudo) => pseudo.remove());
|
|
4297
|
-
trailingPseudos.prepend(pseudos[0]);
|
|
4298
|
-
}
|
|
4299
|
-
if (trailingPseudos.nodes.length) {
|
|
4300
|
-
return [trailingPseudos.toString(), ast.toString()];
|
|
4301
|
-
}
|
|
4302
|
-
return [null, selector];
|
|
4303
|
-
}
|
|
4304
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
4305
|
-
0 && (module.exports = {
|
|
4306
|
-
Breakpoints,
|
|
4307
|
-
Conditions,
|
|
4308
|
-
Context,
|
|
4309
|
-
FileMatcher,
|
|
4310
|
-
ImportMap,
|
|
4311
|
-
JsxEngine,
|
|
4312
|
-
Layers,
|
|
4313
|
-
Patterns,
|
|
4314
|
-
Recipes,
|
|
4315
|
-
RuleProcessor,
|
|
4316
|
-
StaticCss,
|
|
4317
|
-
StyleDecoder,
|
|
4318
|
-
StyleEncoder,
|
|
4319
|
-
Stylesheet,
|
|
4320
|
-
Utility,
|
|
4321
|
-
expandNestedCss,
|
|
4322
|
-
extractParentSelectors,
|
|
4323
|
-
extractTrailingPseudos,
|
|
4324
|
-
messages,
|
|
4325
|
-
optimizeCss,
|
|
4326
|
-
stringify
|
|
4327
|
-
});
|