rainbowindex 0.3.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +135 -0
- package/README.md +27 -4
- package/dist/browser.d.ts +2 -2
- package/dist/browser.mjs +1 -1
- package/dist/chunk-3HRMFZGE.mjs +19 -0
- package/dist/{chunk-AZXWJ625.mjs → chunk-53WD6U2X.mjs} +826 -610
- package/dist/{chunk-IE6N76PW.mjs → chunk-6GTG5SZJ.mjs} +5269 -4660
- package/dist/{chunk-AUWGHSTO.mjs → chunk-IYIUS7AE.mjs} +64 -126
- package/dist/{chunk-SOMDX7V6.mjs → chunk-KRZL4IDK.mjs} +337 -421
- package/dist/chunk-WYMCN5OC.mjs +244 -0
- package/dist/cli.mjs +280 -277
- package/dist/{index-CfDtWufj.d.ts → context-ruu2x_jR.d.ts} +15 -70
- package/dist/editor.d.ts +98 -28
- package/dist/editor.mjs +37 -8
- package/dist/{index-DK6APAGD.d.ts → index-Dp6i5TSv.d.ts} +16 -12
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +4 -4
- package/dist/safelist-D9-Plqta.d.ts +109 -0
- package/dist/vite.mjs +80 -83
- package/package.json +2 -1
- package/dist/chunk-RHOQSN2B.mjs +0 -691
- package/dist/safelist-CH3_PywB.d.ts +0 -43
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
resolveGoogleFonts,
|
|
5
|
-
validateGlobPattern
|
|
6
|
-
} from "./chunk-AZXWJ625.mjs";
|
|
2
|
+
compileScannedProject
|
|
3
|
+
} from "./chunk-53WD6U2X.mjs";
|
|
7
4
|
import {
|
|
8
5
|
APPLY_ALIASES,
|
|
9
|
-
DEFAULT_PROPERTY_GROUP,
|
|
10
6
|
DIRECTIVE_NAMES_SET,
|
|
11
7
|
MAX_DIRECTIVE_INPUT_SIZE,
|
|
12
|
-
PROPERTY_GROUPS,
|
|
13
8
|
RI_IMPORT_SPECIFIER_ALTERNATION,
|
|
14
|
-
|
|
9
|
+
applyVariantWrappers,
|
|
15
10
|
compileCSSFunctions,
|
|
11
|
+
computeSortKey,
|
|
16
12
|
expandVariantGroups,
|
|
17
13
|
forEachApplyClass,
|
|
18
14
|
getCustomUtility,
|
|
@@ -22,17 +18,18 @@ import {
|
|
|
22
18
|
parseUtility,
|
|
23
19
|
pushWarningsDeduped,
|
|
24
20
|
resolveUtilityDeclarations,
|
|
25
|
-
resolveVariant
|
|
26
|
-
|
|
21
|
+
resolveVariant,
|
|
22
|
+
splitSelectorList
|
|
23
|
+
} from "./chunk-6GTG5SZJ.mjs";
|
|
27
24
|
|
|
28
25
|
// src/integrations/postcss/index.ts
|
|
29
|
-
import
|
|
26
|
+
import postcss2 from "postcss";
|
|
30
27
|
import { isAbsolute } from "path";
|
|
31
28
|
|
|
32
29
|
// src/integrations/postcss/apply.ts
|
|
30
|
+
import postcss from "postcss";
|
|
33
31
|
function makeDeclGroup(r) {
|
|
34
|
-
const
|
|
35
|
-
const sortKey = PROPERTY_GROUPS[firstProp] ?? DEFAULT_PROPERTY_GROUP;
|
|
32
|
+
const sortKey = computeSortKey(r.declarations[0]?.property ?? "");
|
|
36
33
|
return {
|
|
37
34
|
sortKey,
|
|
38
35
|
decls: r.declarations.map((d) => ({ decl: d, important: r.important }))
|
|
@@ -46,11 +43,8 @@ function flattenGroups(groups) {
|
|
|
46
43
|
}
|
|
47
44
|
var MAX_APPLY_DEPTH = 5;
|
|
48
45
|
var MAX_APPLY_CLASSES = 500;
|
|
49
|
-
function applySource(node,
|
|
50
|
-
if (source
|
|
51
|
-
const sourceNode = source;
|
|
52
|
-
if (sourceNode.source) node.source = sourceNode.source;
|
|
53
|
-
}
|
|
46
|
+
function applySource(node, from) {
|
|
47
|
+
if (from.source) node.source = from.source;
|
|
54
48
|
return node;
|
|
55
49
|
}
|
|
56
50
|
var GROUP_VARIANT_RE = /^\.group(.+) &$/;
|
|
@@ -70,22 +64,6 @@ function findGroupAncestor(startRule, groupRoots) {
|
|
|
70
64
|
}
|
|
71
65
|
return null;
|
|
72
66
|
}
|
|
73
|
-
function splitSelectorList(selector) {
|
|
74
|
-
const results = [];
|
|
75
|
-
let depth = 0;
|
|
76
|
-
let start = 0;
|
|
77
|
-
for (let i = 0; i < selector.length; i++) {
|
|
78
|
-
const ch = selector[i];
|
|
79
|
-
if (ch === "(" || ch === "[") depth++;
|
|
80
|
-
else if (ch === ")" || ch === "]") depth--;
|
|
81
|
-
else if (ch === "," && depth === 0) {
|
|
82
|
-
results.push(selector.slice(start, i).trim());
|
|
83
|
-
start = i + 1;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
results.push(selector.slice(start).trim());
|
|
87
|
-
return results.filter(Boolean);
|
|
88
|
-
}
|
|
89
67
|
function composeNestedSelectors(parts) {
|
|
90
68
|
if (parts.length === 0) return "";
|
|
91
69
|
let branches = splitSelectorList(parts[0]);
|
|
@@ -116,18 +94,7 @@ function resolveFullNestingSelector(rule) {
|
|
|
116
94
|
}
|
|
117
95
|
return composeNestedSelectors(parts);
|
|
118
96
|
}
|
|
119
|
-
function
|
|
120
|
-
let current = node;
|
|
121
|
-
while (current.parent) {
|
|
122
|
-
current = current.parent;
|
|
123
|
-
}
|
|
124
|
-
return current;
|
|
125
|
-
}
|
|
126
|
-
function processApply(root, theme, warnings, postcss2) {
|
|
127
|
-
if (!postcss2) {
|
|
128
|
-
warnings.push("[RI-1006] @apply requires postcss but it was not provided.");
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
97
|
+
function processApply(root, theme, warnings) {
|
|
131
98
|
for (const alias of APPLY_ALIASES) {
|
|
132
99
|
root.walkAtRules(alias, (atRule) => {
|
|
133
100
|
atRule.name = "apply";
|
|
@@ -135,6 +102,7 @@ function processApply(root, theme, warnings, postcss2) {
|
|
|
135
102
|
}
|
|
136
103
|
const customVariantMap = new Map(theme.customVariants.map((cv) => [cv.name, cv]));
|
|
137
104
|
const checkedApplyRoots = /* @__PURE__ */ new Set();
|
|
105
|
+
const resolveCache = /* @__PURE__ */ new Map();
|
|
138
106
|
for (let depth = 0; depth < MAX_APPLY_DEPTH; depth++) {
|
|
139
107
|
const applyNodes = [];
|
|
140
108
|
const classListByNode = /* @__PURE__ */ new Map();
|
|
@@ -159,9 +127,9 @@ function processApply(root, theme, warnings, postcss2) {
|
|
|
159
127
|
theme,
|
|
160
128
|
warnings,
|
|
161
129
|
customVariantMap,
|
|
162
|
-
postcss2,
|
|
163
130
|
groupRoots,
|
|
164
|
-
checkedApplyRoots
|
|
131
|
+
checkedApplyRoots,
|
|
132
|
+
resolveCache
|
|
165
133
|
);
|
|
166
134
|
}
|
|
167
135
|
}
|
|
@@ -178,7 +146,7 @@ function processApply(root, theme, warnings, postcss2) {
|
|
|
178
146
|
}
|
|
179
147
|
}
|
|
180
148
|
}
|
|
181
|
-
function expandApply(atRule, classNames, theme, warnings, customVariantMap,
|
|
149
|
+
function expandApply(atRule, classNames, theme, warnings, customVariantMap, groupRoots, checkedApplyRoots, resolveCache) {
|
|
182
150
|
const parentRule = atRule.parent;
|
|
183
151
|
if (parentRule?.type !== "rule") {
|
|
184
152
|
warnings.push("[RI-1006] @apply must be used inside a CSS rule, not at the top level.");
|
|
@@ -200,8 +168,23 @@ function expandApply(atRule, classNames, theme, warnings, customVariantMap, post
|
|
|
200
168
|
}
|
|
201
169
|
const resolved = [];
|
|
202
170
|
for (const className of classNames) {
|
|
203
|
-
|
|
204
|
-
if (
|
|
171
|
+
let entry = resolveCache.get(className);
|
|
172
|
+
if (!entry) {
|
|
173
|
+
const entryWarnings = [];
|
|
174
|
+
entry = {
|
|
175
|
+
result: resolveClassName(
|
|
176
|
+
className,
|
|
177
|
+
theme,
|
|
178
|
+
entryWarnings,
|
|
179
|
+
customVariantMap,
|
|
180
|
+
checkedApplyRoots
|
|
181
|
+
),
|
|
182
|
+
warnings: entryWarnings
|
|
183
|
+
};
|
|
184
|
+
resolveCache.set(className, entry);
|
|
185
|
+
}
|
|
186
|
+
warnings.push(...entry.warnings);
|
|
187
|
+
if (entry.result) resolved.push(entry.result);
|
|
205
188
|
}
|
|
206
189
|
const baseGroups = [];
|
|
207
190
|
const baseNestedBlocks = [];
|
|
@@ -245,7 +228,7 @@ function expandApply(atRule, classNames, theme, warnings, customVariantMap, post
|
|
|
245
228
|
}
|
|
246
229
|
for (const { decl, important } of flattenGroups(baseGroups)) {
|
|
247
230
|
const node = applySource(
|
|
248
|
-
|
|
231
|
+
postcss.decl({
|
|
249
232
|
prop: decl.property,
|
|
250
233
|
value: decl.value,
|
|
251
234
|
important
|
|
@@ -255,15 +238,15 @@ function expandApply(atRule, classNames, theme, warnings, customVariantMap, post
|
|
|
255
238
|
atRule.before(node);
|
|
256
239
|
}
|
|
257
240
|
for (const { block, important } of baseNestedBlocks) {
|
|
258
|
-
atRule.before(buildNestedBlockNode(block,
|
|
241
|
+
atRule.before(buildNestedBlockNode(block, atRule, important));
|
|
259
242
|
}
|
|
260
243
|
let insertAfter = parentRule;
|
|
261
244
|
for (const [nestedSel, groups] of nestedGroups) {
|
|
262
245
|
const sel = nestedSel.replaceAll("&", baseSelector);
|
|
263
|
-
const rule = applySource(
|
|
246
|
+
const rule = applySource(postcss.rule({ selector: sel }), parentRule);
|
|
264
247
|
for (const { decl, important } of flattenGroups(groups)) {
|
|
265
248
|
rule.append(
|
|
266
|
-
applySource(
|
|
249
|
+
applySource(postcss.decl({ prop: decl.property, value: decl.value, important }), atRule)
|
|
267
250
|
);
|
|
268
251
|
}
|
|
269
252
|
parentContainer.insertAfter(insertAfter, rule);
|
|
@@ -284,7 +267,7 @@ function expandApply(atRule, classNames, theme, warnings, customVariantMap, post
|
|
|
284
267
|
};
|
|
285
268
|
let docRootMemo = null;
|
|
286
269
|
const docRoot = () => {
|
|
287
|
-
if (docRootMemo === null) docRootMemo =
|
|
270
|
+
if (docRootMemo === null) docRootMemo = parentContainer.root();
|
|
288
271
|
return docRootMemo;
|
|
289
272
|
};
|
|
290
273
|
for (const [key, bucket] of variantBuckets) {
|
|
@@ -313,7 +296,6 @@ function expandApply(atRule, classNames, theme, warnings, customVariantMap, post
|
|
|
313
296
|
effectiveBase,
|
|
314
297
|
groupVariantInfo.rewrittenWrappers,
|
|
315
298
|
bucketDecls,
|
|
316
|
-
postcss2,
|
|
317
299
|
atRule,
|
|
318
300
|
bucket.nestedSelector,
|
|
319
301
|
bucket.nestedBlocks
|
|
@@ -326,7 +308,6 @@ function expandApply(atRule, classNames, theme, warnings, customVariantMap, post
|
|
|
326
308
|
fullNestingSelector(),
|
|
327
309
|
bucket.wrappers,
|
|
328
310
|
bucketDecls,
|
|
329
|
-
postcss2,
|
|
330
311
|
atRule,
|
|
331
312
|
bucket.nestedSelector,
|
|
332
313
|
bucket.nestedBlocks
|
|
@@ -339,7 +320,6 @@ function expandApply(atRule, classNames, theme, warnings, customVariantMap, post
|
|
|
339
320
|
baseSelector,
|
|
340
321
|
bucket.wrappers,
|
|
341
322
|
bucketDecls,
|
|
342
|
-
postcss2,
|
|
343
323
|
atRule,
|
|
344
324
|
bucket.nestedSelector,
|
|
345
325
|
bucket.nestedBlocks
|
|
@@ -451,60 +431,41 @@ function variantKey(wrappers, nestedSelector) {
|
|
|
451
431
|
if (nestedSelector) key += `\0N${nestedSelector}`;
|
|
452
432
|
return key;
|
|
453
433
|
}
|
|
454
|
-
function buildNestedBlockNode(block,
|
|
434
|
+
function buildNestedBlockNode(block, sourceNode, important) {
|
|
455
435
|
let node;
|
|
456
436
|
if (block.selector.charCodeAt(0) === 64) {
|
|
457
437
|
const spaceIdx = block.selector.indexOf(" ");
|
|
458
438
|
const name = spaceIdx === -1 ? block.selector.slice(1) : block.selector.slice(1, spaceIdx);
|
|
459
439
|
const params = spaceIdx === -1 ? "" : block.selector.slice(spaceIdx + 1);
|
|
460
|
-
node = applySource(
|
|
440
|
+
node = applySource(postcss.atRule({ name, params }), sourceNode);
|
|
461
441
|
} else {
|
|
462
|
-
node = applySource(
|
|
442
|
+
node = applySource(postcss.rule({ selector: block.selector }), sourceNode);
|
|
463
443
|
}
|
|
464
444
|
for (const d of block.declarations) {
|
|
465
445
|
node.append(
|
|
466
|
-
applySource(
|
|
446
|
+
applySource(postcss.decl({ prop: d.property, value: d.value, important }), sourceNode)
|
|
467
447
|
);
|
|
468
448
|
}
|
|
469
449
|
for (const child of block.nested) {
|
|
470
|
-
node.append(buildNestedBlockNode(child,
|
|
450
|
+
node.append(buildNestedBlockNode(child, sourceNode, important));
|
|
471
451
|
}
|
|
472
452
|
return node;
|
|
473
453
|
}
|
|
474
|
-
function buildVariantNode(baseSelector, wrappers, decls,
|
|
454
|
+
function buildVariantNode(baseSelector, wrappers, decls, sourceNode, nestedSelector, nestedBlocks) {
|
|
475
455
|
if (decls.length === 0 && nestedBlocks.length === 0) return null;
|
|
476
|
-
|
|
477
|
-
const
|
|
478
|
-
let startingStyle = false;
|
|
479
|
-
for (const w of wrappers) {
|
|
480
|
-
if (w.selectorSuffix) {
|
|
481
|
-
const branches = splitSelectorList(selector);
|
|
482
|
-
const suffix = w.selectorSuffix;
|
|
483
|
-
if (w.replaceAmpersand) {
|
|
484
|
-
selector = branches.map((b) => suffix.replace(/&/g, b)).join(", ");
|
|
485
|
-
} else {
|
|
486
|
-
selector = branches.map((b) => b + suffix).join(", ");
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
if (w.atRule) {
|
|
490
|
-
atRules.push(w.atRule);
|
|
491
|
-
}
|
|
492
|
-
if (w.startingStyle) {
|
|
493
|
-
startingStyle = true;
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
const rule = applySource(postcss2.rule({ selector }), sourceNode);
|
|
456
|
+
const { selector, atRules, startingStyle } = applyVariantWrappers(baseSelector, wrappers);
|
|
457
|
+
const rule = applySource(postcss.rule({ selector }), sourceNode);
|
|
497
458
|
let declTarget = rule;
|
|
498
459
|
if (nestedSelector) {
|
|
499
|
-
declTarget = applySource(
|
|
460
|
+
declTarget = applySource(postcss.rule({ selector: nestedSelector }), sourceNode);
|
|
500
461
|
rule.append(declTarget);
|
|
501
462
|
}
|
|
502
463
|
if (startingStyle) {
|
|
503
|
-
const startingAtRule = applySource(
|
|
464
|
+
const startingAtRule = applySource(postcss.atRule({ name: "starting-style" }), sourceNode);
|
|
504
465
|
for (const { decl, important } of decls) {
|
|
505
466
|
startingAtRule.append(
|
|
506
467
|
applySource(
|
|
507
|
-
|
|
468
|
+
postcss.decl({ prop: decl.property, value: decl.value, important }),
|
|
508
469
|
sourceNode
|
|
509
470
|
)
|
|
510
471
|
);
|
|
@@ -514,14 +475,14 @@ function buildVariantNode(baseSelector, wrappers, decls, postcss2, sourceNode, n
|
|
|
514
475
|
for (const { decl, important } of decls) {
|
|
515
476
|
declTarget.append(
|
|
516
477
|
applySource(
|
|
517
|
-
|
|
478
|
+
postcss.decl({ prop: decl.property, value: decl.value, important }),
|
|
518
479
|
sourceNode
|
|
519
480
|
)
|
|
520
481
|
);
|
|
521
482
|
}
|
|
522
483
|
}
|
|
523
484
|
for (const { block, important } of nestedBlocks) {
|
|
524
|
-
declTarget.append(buildNestedBlockNode(block,
|
|
485
|
+
declTarget.append(buildNestedBlockNode(block, sourceNode, important));
|
|
525
486
|
}
|
|
526
487
|
if (atRules.length === 0) return rule;
|
|
527
488
|
let node = rule;
|
|
@@ -530,7 +491,7 @@ function buildVariantNode(baseSelector, wrappers, decls, postcss2, sourceNode, n
|
|
|
530
491
|
const spaceIdx = atRuleStr.indexOf(" ");
|
|
531
492
|
const name = spaceIdx === -1 ? atRuleStr.slice(1) : atRuleStr.slice(1, spaceIdx);
|
|
532
493
|
const params = spaceIdx === -1 ? "" : atRuleStr.slice(spaceIdx + 1);
|
|
533
|
-
const wrapper = applySource(
|
|
494
|
+
const wrapper = applySource(postcss.atRule({ name, params }), sourceNode);
|
|
534
495
|
wrapper.append(node);
|
|
535
496
|
node = wrapper;
|
|
536
497
|
}
|
|
@@ -603,48 +564,25 @@ var rainbowindex = (options = {}) => {
|
|
|
603
564
|
if (!hasActivation) {
|
|
604
565
|
return;
|
|
605
566
|
}
|
|
606
|
-
const
|
|
607
|
-
const compilationWarnings = analysis.warnings;
|
|
608
|
-
const warningSeen = analysis.warningSeen;
|
|
609
|
-
const theme = analysis.theme;
|
|
610
|
-
const sourceOverrides = [];
|
|
611
|
-
if (options.sources) {
|
|
612
|
-
for (const s of options.sources) {
|
|
613
|
-
const err = validateGlobPattern(s);
|
|
614
|
-
if (err) {
|
|
615
|
-
pushWarningsDeduped(compilationWarnings, [`[RI-1015] ${err}`], warningSeen);
|
|
616
|
-
continue;
|
|
617
|
-
}
|
|
618
|
-
sourceOverrides.push({ pattern: s, negated: false, inline: false });
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
const scannedClasses = await collectProjectClasses(
|
|
622
|
-
theme.sources,
|
|
623
|
-
sourceOverrides,
|
|
624
|
-
cwd,
|
|
625
|
-
compilationWarnings,
|
|
626
|
-
warningSeen
|
|
627
|
-
);
|
|
628
|
-
const from = root.source?.input?.file ?? root.source?.input?.id ?? root.source?.input?.from ?? "<rainbowindex>";
|
|
629
|
-
const compiled = await finalizeProjectCompilation({
|
|
567
|
+
const { compiled, warningSeen } = await compileScannedProject({
|
|
630
568
|
css: rawCSS,
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
// compileProject, so all surfaces emit identical bytes on slow networks.
|
|
635
|
-
resolveFonts: resolveGoogleFonts
|
|
569
|
+
cwd,
|
|
570
|
+
surfacePatterns: options.sources,
|
|
571
|
+
onInvalidPattern: (err) => `[RI-1015] ${err}`
|
|
636
572
|
});
|
|
573
|
+
const compilationWarnings = compiled.warnings;
|
|
574
|
+
const from = root.source?.input?.file ?? root.source?.input?.id ?? root.source?.input?.from ?? "<rainbowindex>";
|
|
637
575
|
stripRIDirectiveNodes(root);
|
|
638
|
-
if (compiled.sections.length > 0) {
|
|
639
|
-
const generatedRoot = postcss.parse(compiled.sections.join("\n\n"), { from });
|
|
640
|
-
root.prepend(generatedRoot.nodes);
|
|
641
|
-
}
|
|
642
576
|
const slotWarnings = [];
|
|
643
577
|
warnStandaloneSlots(root, slotWarnings);
|
|
644
578
|
pushWarningsDeduped(compilationWarnings, slotWarnings, warningSeen);
|
|
645
579
|
const applyWarnings = [];
|
|
646
|
-
processApply(root, compiled.theme, applyWarnings
|
|
580
|
+
processApply(root, compiled.theme, applyWarnings);
|
|
647
581
|
pushWarningsDeduped(compilationWarnings, applyWarnings, warningSeen);
|
|
582
|
+
if (compiled.sections.length > 0) {
|
|
583
|
+
const generatedRoot = postcss2.parse(compiled.sections.join("\n\n"), { from });
|
|
584
|
+
root.prepend(generatedRoot.nodes);
|
|
585
|
+
}
|
|
648
586
|
const cssFnWarnings = [];
|
|
649
587
|
processCSSFunctions(root, compiled.theme, cssFnWarnings);
|
|
650
588
|
pushWarningsDeduped(compilationWarnings, cssFnWarnings, warningSeen);
|