rainbowindex 0.4.1 → 0.5.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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  compileScannedProject
3
- } from "./chunk-53WD6U2X.mjs";
3
+ } from "./chunk-F4VCBISU.mjs";
4
4
  import {
5
5
  APPLY_ALIASES,
6
6
  DIRECTIVE_NAMES_SET,
@@ -11,16 +11,16 @@ import {
11
11
  computeSortKey,
12
12
  expandVariantGroups,
13
13
  forEachApplyClass,
14
- getCustomUtility,
15
14
  hasApplyLikeDirective,
16
15
  hasCSSFunctions,
17
16
  hasRIActivation,
17
+ matchCustomUtility,
18
18
  parseUtility,
19
19
  pushWarningsDeduped,
20
20
  resolveUtilityDeclarations,
21
21
  resolveVariant,
22
22
  splitSelectorList
23
- } from "./chunk-6GTG5SZJ.mjs";
23
+ } from "./chunk-PDORZSQX.mjs";
24
24
 
25
25
  // src/integrations/postcss/index.ts
26
26
  import postcss2 from "postcss";
@@ -28,6 +28,7 @@ import { isAbsolute } from "path";
28
28
 
29
29
  // src/integrations/postcss/apply.ts
30
30
  import postcss from "postcss";
31
+ var applyStateByTheme = /* @__PURE__ */ new WeakMap();
31
32
  function makeDeclGroup(r) {
32
33
  const sortKey = computeSortKey(r.declarations[0]?.property ?? "");
33
34
  return {
@@ -100,9 +101,16 @@ function processApply(root, theme, warnings) {
100
101
  atRule.name = "apply";
101
102
  });
102
103
  }
103
- const customVariantMap = new Map(theme.customVariants.map((cv) => [cv.name, cv]));
104
- const checkedApplyRoots = /* @__PURE__ */ new Set();
105
- const resolveCache = /* @__PURE__ */ new Map();
104
+ let state = applyStateByTheme.get(theme);
105
+ if (!state) {
106
+ state = {
107
+ customVariantMap: new Map(theme.customVariants.map((cv) => [cv.name, cv])),
108
+ applyRootWarnings: /* @__PURE__ */ new Map(),
109
+ resolveCache: /* @__PURE__ */ new Map()
110
+ };
111
+ applyStateByTheme.set(theme, state);
112
+ }
113
+ const { customVariantMap, applyRootWarnings, resolveCache } = state;
106
114
  for (let depth = 0; depth < MAX_APPLY_DEPTH; depth++) {
107
115
  const applyNodes = [];
108
116
  const classListByNode = /* @__PURE__ */ new Map();
@@ -128,7 +136,7 @@ function processApply(root, theme, warnings) {
128
136
  warnings,
129
137
  customVariantMap,
130
138
  groupRoots,
131
- checkedApplyRoots,
139
+ applyRootWarnings,
132
140
  resolveCache
133
141
  );
134
142
  }
@@ -146,7 +154,7 @@ function processApply(root, theme, warnings) {
146
154
  }
147
155
  }
148
156
  }
149
- function expandApply(atRule, classNames, theme, warnings, customVariantMap, groupRoots, checkedApplyRoots, resolveCache) {
157
+ function expandApply(atRule, classNames, theme, warnings, customVariantMap, groupRoots, applyRootWarnings, resolveCache) {
150
158
  const parentRule = atRule.parent;
151
159
  if (parentRule?.type !== "rule") {
152
160
  warnings.push("[RI-1006] @apply must be used inside a CSS rule, not at the top level.");
@@ -177,7 +185,7 @@ function expandApply(atRule, classNames, theme, warnings, customVariantMap, grou
177
185
  theme,
178
186
  entryWarnings,
179
187
  customVariantMap,
180
- checkedApplyRoots
188
+ applyRootWarnings
181
189
  ),
182
190
  warnings: entryWarnings
183
191
  };
@@ -252,19 +260,24 @@ function expandApply(atRule, classNames, theme, warnings, customVariantMap, grou
252
260
  parentContainer.insertAfter(insertAfter, rule);
253
261
  insertAfter = rule;
254
262
  }
255
- const groupInfoByKey = /* @__PURE__ */ new Map();
256
- let hasGroupVariants = false;
257
- for (const [key, bucket] of variantBuckets) {
258
- const info = resolveGroupVariantInfo(bucket.wrappers, parentRule, groupRoots);
259
- groupInfoByKey.set(key, info);
260
- if (info) hasGroupVariants = true;
261
- }
262
263
  let fullSelectorMemo = null;
263
264
  const fullNestingSelector = () => {
264
265
  if (fullSelectorMemo === null)
265
266
  fullSelectorMemo = resolveFullNestingSelector(parentRule);
266
267
  return fullSelectorMemo;
267
268
  };
269
+ const groupInfoByKey = /* @__PURE__ */ new Map();
270
+ let hasGroupVariants = false;
271
+ for (const [key, bucket] of variantBuckets) {
272
+ const info = resolveGroupVariantInfo(
273
+ bucket.wrappers,
274
+ parentRule,
275
+ groupRoots,
276
+ fullNestingSelector
277
+ );
278
+ groupInfoByKey.set(key, info);
279
+ if (info) hasGroupVariants = true;
280
+ }
268
281
  let docRootMemo = null;
269
282
  const docRoot = () => {
270
283
  if (docRootMemo === null) docRootMemo = parentContainer.root();
@@ -276,7 +289,7 @@ function expandApply(atRule, classNames, theme, warnings, customVariantMap, grou
276
289
  if (groupVariantInfo) {
277
290
  const fullSelector = fullNestingSelector();
278
291
  const { groupRootSelector } = groupVariantInfo;
279
- const rootBranches = splitSelectorList(groupRootSelector);
292
+ const rootBranches = groupVariantInfo.isSelf ? [] : splitSelectorList(groupRootSelector);
280
293
  const fullBranches = splitSelectorList(fullSelector);
281
294
  const baseBranches = [];
282
295
  for (const fb of fullBranches) {
@@ -332,7 +345,7 @@ function expandApply(atRule, classNames, theme, warnings, customVariantMap, grou
332
345
  }
333
346
  atRule.remove();
334
347
  }
335
- function resolveGroupVariantInfo(wrappers, parentRule, groupRoots) {
348
+ function resolveGroupVariantInfo(wrappers, parentRule, groupRoots, fullNestingSelector) {
336
349
  if (groupRoots.size === 0) return null;
337
350
  const hasGroupVariant = wrappers.some(
338
351
  (w) => w.selectorSuffix && w.replaceAmpersand && GROUP_VARIANT_RE.test(w.selectorSuffix)
@@ -340,23 +353,23 @@ function resolveGroupVariantInfo(wrappers, parentRule, groupRoots) {
340
353
  if (!hasGroupVariant) return null;
341
354
  const groupInfo = findGroupAncestor(parentRule, groupRoots);
342
355
  if (!groupInfo) return null;
356
+ const isSelf = fullNestingSelector() === groupInfo.groupRootSelector;
343
357
  const rewrittenWrappers = wrappers.map((w) => {
344
358
  if (!w.selectorSuffix || !w.replaceAmpersand) return w;
345
359
  const match = w.selectorSuffix.match(GROUP_VARIANT_RE);
346
360
  if (!match) return w;
347
361
  const pseudo = match[1];
362
+ if (isSelf) return { ...w, selectorSuffix: `&${pseudo}` };
348
363
  const rootBranches = splitSelectorList(groupInfo.groupRootSelector);
349
364
  const newSuffix = rootBranches.map((b) => `${b}${pseudo} &`).join(", ");
350
365
  return { ...w, selectorSuffix: newSuffix };
351
366
  });
352
- return { rewrittenWrappers, groupRootSelector: groupInfo.groupRootSelector };
367
+ return { rewrittenWrappers, groupRootSelector: groupInfo.groupRootSelector, isSelf };
353
368
  }
354
369
  var MARKER_CLASSES = /* @__PURE__ */ new Set(["group"]);
355
370
  var MAX_CUSTOM_APPLY_DEPTH = 5;
356
- function findCustomUtility(utility, value, theme) {
357
- const target = value === null ? utility : `${utility}-${value}`;
358
- const cu = getCustomUtility(theme, target);
359
- return cu && !cu.functional ? cu : void 0;
371
+ function findCustomUtility(utility, value, negative, theme) {
372
+ return matchCustomUtility(utility, value, negative, theme)?.cu;
360
373
  }
361
374
  function checkCustomApplyWarnings(cu, theme, warnings, visiting = /* @__PURE__ */ new Set()) {
362
375
  if (!hasApplyLikeDirective(cu.body)) return;
@@ -378,12 +391,12 @@ function checkCustomApplyWarnings(cu, theme, warnings, visiting = /* @__PURE__ *
378
391
  visiting.add(cu.name);
379
392
  for (const innerClass of innerClasses) {
380
393
  const parsed = parseUtility(innerClass);
381
- const innerCu = findCustomUtility(parsed.utility, parsed.value, theme);
394
+ const innerCu = findCustomUtility(parsed.utility, parsed.value, parsed.negative, theme);
382
395
  if (innerCu) checkCustomApplyWarnings(innerCu, theme, warnings, visiting);
383
396
  }
384
397
  visiting.delete(cu.name);
385
398
  }
386
- function resolveClassName(className, theme, warnings, customVariantMap, checkedApplyRoots) {
399
+ function resolveClassName(className, theme, warnings, customVariantMap, applyRootWarnings) {
387
400
  const parsed = parseUtility(className);
388
401
  if (parsed.variants.length === 0 && MARKER_CLASSES.has(parsed.utility) && parsed.value === null) {
389
402
  return null;
@@ -394,10 +407,15 @@ function resolveClassName(className, theme, warnings, customVariantMap, checkedA
394
407
  return null;
395
408
  }
396
409
  const declarations = [...utilResult.declarations];
397
- const cu = findCustomUtility(parsed.utility, parsed.value, theme);
398
- if (cu && !checkedApplyRoots.has(cu.name)) {
399
- checkedApplyRoots.add(cu.name);
400
- checkCustomApplyWarnings(cu, theme, warnings);
410
+ const cu = findCustomUtility(parsed.utility, parsed.value, parsed.negative, theme);
411
+ if (cu) {
412
+ let cuWarnings = applyRootWarnings.get(cu.name);
413
+ if (!cuWarnings) {
414
+ cuWarnings = [];
415
+ checkCustomApplyWarnings(cu, theme, cuWarnings);
416
+ applyRootWarnings.set(cu.name, cuWarnings);
417
+ }
418
+ warnings.push(...cuWarnings);
401
419
  }
402
420
  const variantWrappers = [];
403
421
  for (const variant of parsed.variants) {
@@ -437,16 +437,6 @@ var DEFAULT_BREAKPOINTS = {
437
437
  lg: "64rem",
438
438
  xl: "80rem"
439
439
  };
440
- var DEFAULT_ROUNDED_ROOF = "1.5rem";
441
- var DEFAULT_ROUNDED = {
442
- "2xs": "max(0px, calc(var(--rounded-roof) - var(--spacing) * 5))",
443
- xs: "max(0px, calc(var(--rounded-roof) - var(--spacing) * 4))",
444
- sm: "max(0px, calc(var(--rounded-roof) - var(--spacing) * 3))",
445
- md: "max(0px, calc(var(--rounded-roof) - var(--spacing) * 2))",
446
- lg: "max(0px, calc(var(--rounded-roof) - var(--spacing)))",
447
- xl: "var(--rounded-roof)",
448
- full: "calc(infinity * 1px)"
449
- };
450
440
  var CORNER_SHAPE_KEYWORDS = [
451
441
  "round",
452
442
  "scoop",
@@ -608,7 +598,6 @@ var defaultTheme = Object.freeze({
608
598
  colors: DEFAULT_COLORS,
609
599
  text: DEFAULT_TEXT,
610
600
  breakpoints: DEFAULT_BREAKPOINTS,
611
- rounded: DEFAULT_ROUNDED,
612
601
  shadows: DEFAULT_SHADOWS,
613
602
  weights: DEFAULT_WEIGHTS,
614
603
  easing: DEFAULT_EASING,
@@ -1230,7 +1219,7 @@ addAll(
1230
1219
  ],
1231
1220
  ["border-style"]
1232
1221
  );
1233
- addAll(["rounded", "rounded-none", "rounded-full"], ["border-radius"]);
1222
+ addAll(["rounded-none", "rounded-full"], ["border-radius"]);
1234
1223
  addAll(
1235
1224
  [
1236
1225
  "corner-round",
@@ -2182,7 +2171,7 @@ var DIRECTIONAL_BORDER_COLOR_PROPS = new Map(
2182
2171
  "border-y"
2183
2172
  ].map((prefix) => [prefix, Object.freeze([PREFIX_PROPS[prefix][0].replace("width", "color")])])
2184
2173
  );
2185
- function resolvePropsWith(utility, customStaticProps, textSizes, fontFamilies, colorNames) {
2174
+ function resolvePropsWith(utility, customStaticProps, customFunctionalProps, textSizes, fontFamilies, colorNames) {
2186
2175
  if (utility.charCodeAt(0) === 91) {
2187
2176
  const colonIdx = utility.indexOf(":");
2188
2177
  if (colonIdx !== -1) {
@@ -2198,6 +2187,10 @@ function resolvePropsWith(utility, customStaticProps, textSizes, fontFamilies, c
2198
2187
  if (Object.hasOwn(customStaticProps, name)) return customStaticProps[name];
2199
2188
  const builtin = BUILTIN_STATIC_PROPS[name];
2200
2189
  if (builtin !== void 0) return builtin;
2190
+ for (const [root, properties] of customFunctionalProps) {
2191
+ if (name.length <= root.length) continue;
2192
+ if (name.startsWith(root) && name.charCodeAt(root.length) === 45) return properties;
2193
+ }
2201
2194
  const firstDash = name.indexOf("-");
2202
2195
  const firstSeg = firstDash === -1 ? name : name.slice(0, firstDash);
2203
2196
  const candidates = PREFIX_FIRST_SEGMENT_MAP.get(firstSeg);
@@ -2223,6 +2216,7 @@ function resolvePropsWith(utility, customStaticProps, textSizes, fontFamilies, c
2223
2216
 
2224
2217
  // src/merge/context.ts
2225
2218
  var _customStaticProps = {};
2219
+ var _customFunctionalProps = [];
2226
2220
  var _textSizes = new Set(DEFAULT_TEXT_SIZES);
2227
2221
  var _fontFamilies = new Set(DEFAULT_FONT_FAMILIES);
2228
2222
  var _colorNames = /* @__PURE__ */ new Set();
@@ -2230,13 +2224,54 @@ var _latestSnapshot = null;
2230
2224
  function hasFinalizedSnapshot() {
2231
2225
  return _latestSnapshot !== null;
2232
2226
  }
2233
- var defaultRiCache = /* @__PURE__ */ new Map();
2227
+ var RI_CACHE_MAX = 500;
2228
+ var RiCache = class {
2229
+ constructor(maxSize) {
2230
+ this.maxSize = maxSize;
2231
+ }
2232
+ maxSize;
2233
+ current = /* @__PURE__ */ new Map();
2234
+ previous = /* @__PURE__ */ new Map();
2235
+ get(key) {
2236
+ const hit = this.current.get(key);
2237
+ if (hit !== void 0) return hit;
2238
+ const promoted = this.previous.get(key);
2239
+ if (promoted !== void 0) this.put(key, promoted);
2240
+ return promoted;
2241
+ }
2242
+ put(key, value) {
2243
+ this.current.set(key, value);
2244
+ if (this.current.size >= this.maxSize) {
2245
+ this.previous = this.current;
2246
+ this.current = /* @__PURE__ */ new Map();
2247
+ }
2248
+ }
2249
+ has(key) {
2250
+ return this.current.has(key) || this.previous.has(key);
2251
+ }
2252
+ get size() {
2253
+ return this.current.size + this.previous.size;
2254
+ }
2255
+ clear() {
2256
+ this.current.clear();
2257
+ this.previous.clear();
2258
+ }
2259
+ };
2260
+ var defaultRiCache = new RiCache(RI_CACHE_MAX);
2234
2261
  function resolveProps(utility) {
2235
- return resolvePropsWith(utility, _customStaticProps, _textSizes, _fontFamilies, _colorNames);
2262
+ return resolvePropsWith(
2263
+ utility,
2264
+ _customStaticProps,
2265
+ _customFunctionalProps,
2266
+ _textSizes,
2267
+ _fontFamilies,
2268
+ _colorNames
2269
+ );
2236
2270
  }
2237
2271
  function resolverFor(snapshot) {
2238
2272
  const snap = snapshot ?? _latestSnapshot ?? {
2239
2273
  customStaticProps: _customStaticProps,
2274
+ customFunctionalProps: _customFunctionalProps,
2240
2275
  textSizes: _textSizes,
2241
2276
  fontFamilies: _fontFamilies,
2242
2277
  colorNames: _colorNames
@@ -2244,6 +2279,7 @@ function resolverFor(snapshot) {
2244
2279
  return (utility) => resolvePropsWith(
2245
2280
  utility,
2246
2281
  snap.customStaticProps,
2282
+ snap.customFunctionalProps,
2247
2283
  snap.textSizes,
2248
2284
  snap.fontFamilies,
2249
2285
  snap.colorNames
@@ -2252,12 +2288,13 @@ function resolverFor(snapshot) {
2252
2288
  function createCompilationContext() {
2253
2289
  return {
2254
2290
  customStaticProps: {},
2291
+ customFunctionalProps: {},
2255
2292
  textSizes: new Set(DEFAULT_TEXT_SIZES),
2256
2293
  fontFamilies: new Set(DEFAULT_FONT_FAMILIES),
2257
2294
  colorNames: /* @__PURE__ */ new Set()
2258
2295
  };
2259
2296
  }
2260
- function registerCustomUtility(ctx, name, properties) {
2297
+ function registerCustomUtility(ctx, name, properties, functional = false) {
2261
2298
  if (IS_DEV) {
2262
2299
  if (!name) {
2263
2300
  devWarn("[RI-1301] registerCustomUtility() called with empty name \u2014 skipping.");
@@ -2269,7 +2306,8 @@ function registerCustomUtility(ctx, name, properties) {
2269
2306
  );
2270
2307
  }
2271
2308
  }
2272
- ctx.customStaticProps[name] = properties;
2309
+ if (functional) ctx.customFunctionalProps[name] = properties;
2310
+ else ctx.customStaticProps[name] = properties;
2273
2311
  }
2274
2312
  function registerCustomTextSizes(ctx, sizes) {
2275
2313
  for (const s of sizes) ctx.textSizes.add(s);
@@ -2285,6 +2323,7 @@ function snapshotCompilationContext(ctx) {
2285
2323
  customStaticProps: Object.fromEntries(
2286
2324
  Object.entries(ctx.customStaticProps).map(([k, v]) => [k, [...v]])
2287
2325
  ),
2326
+ customFunctionalProps: Object.entries(ctx.customFunctionalProps).map(([k, v]) => [k, [...v]]).sort((a, b) => b[0].length - a[0].length),
2288
2327
  textSizes: new Set(ctx.textSizes),
2289
2328
  fontFamilies: new Set(ctx.fontFamilies),
2290
2329
  colorNames: new Set(ctx.colorNames)
@@ -2293,6 +2332,7 @@ function snapshotCompilationContext(ctx) {
2293
2332
  function finalizeCompilationContext(ctx) {
2294
2333
  const snapshot = snapshotCompilationContext(ctx);
2295
2334
  _customStaticProps = snapshot.customStaticProps;
2335
+ _customFunctionalProps = snapshot.customFunctionalProps;
2296
2336
  _textSizes = snapshot.textSizes;
2297
2337
  _fontFamilies = snapshot.fontFamilies;
2298
2338
  _colorNames = snapshot.colorNames;
@@ -2302,7 +2342,6 @@ function finalizeCompilationContext(ctx) {
2302
2342
  }
2303
2343
 
2304
2344
  // src/merge/index.ts
2305
- var RI_CACHE_MAX = 500;
2306
2345
  var RI_CACHE_KEY_MAX_LEN = 2048;
2307
2346
  var WS_SPLIT_RE = /\s+/;
2308
2347
  function findVariantSplit(cls) {
@@ -2386,37 +2425,15 @@ function mergeUncached(classes, resolve, trace) {
2386
2425
  result.reverse();
2387
2426
  return result.join(" ");
2388
2427
  }
2389
- function evictLRU(cache, maxSize) {
2390
- if (cache.size < maxSize) return;
2391
- const evictCount = maxSize >> 2;
2392
- let count = 0;
2393
- for (const key of cache.keys()) {
2394
- if (count >= evictCount) break;
2395
- cache.delete(key);
2396
- count++;
2397
- }
2398
- }
2399
- function lruGet(cache, key) {
2400
- const cached = cache.get(key);
2401
- if (cached !== void 0) {
2402
- cache.delete(key);
2403
- cache.set(key, cached);
2404
- }
2405
- return cached;
2406
- }
2407
- function lruPut(cache, key, value) {
2408
- evictLRU(cache, RI_CACHE_MAX);
2409
- cache.set(key, value);
2410
- }
2411
2428
  function mergeClasses(classes, resolve, cache) {
2412
2429
  const cacheKey = classes.join("\0");
2413
2430
  const useCache = cacheKey.length <= RI_CACHE_KEY_MAX_LEN;
2414
2431
  if (useCache) {
2415
- const cached = lruGet(cache, cacheKey);
2432
+ const cached = cache.get(cacheKey);
2416
2433
  if (cached !== void 0) return cached;
2417
2434
  }
2418
2435
  const output = mergeUncached(classes, resolve);
2419
- if (useCache) lruPut(cache, cacheKey, output);
2436
+ if (useCache) cache.put(cacheKey, output);
2420
2437
  return output;
2421
2438
  }
2422
2439
  function mergeFrom(inputs, resolve, cache) {
@@ -2434,11 +2451,11 @@ function mergeFrom(inputs, resolve, cache) {
2434
2451
  if (fastPath) {
2435
2452
  if (rawKey === "") return "";
2436
2453
  if (rawKey.length <= RI_CACHE_KEY_MAX_LEN) {
2437
- const cached = lruGet(cache, rawKey);
2454
+ const cached = cache.get(rawKey);
2438
2455
  if (cached !== void 0) return cached;
2439
2456
  const classes2 = flattenInputs(inputs);
2440
2457
  const output = classes2.length === 0 ? "" : classes2.length === 1 ? classes2[0] : mergeUncached(classes2, resolve);
2441
- lruPut(cache, rawKey, output);
2458
+ cache.put(rawKey, output);
2442
2459
  return output;
2443
2460
  }
2444
2461
  }
@@ -2494,7 +2511,7 @@ function ri(...inputs) {
2494
2511
  }
2495
2512
  function createRi(snapshot) {
2496
2513
  const resolve = resolverFor(snapshot);
2497
- const cache = /* @__PURE__ */ new Map();
2514
+ const cache = new RiCache(RI_CACHE_MAX);
2498
2515
  return function boundRi(...inputs) {
2499
2516
  return mergeFrom(inputs, resolve, cache);
2500
2517
  };
@@ -2592,8 +2609,6 @@ export {
2592
2609
  generateThemeOverrides,
2593
2610
  DEFAULT_TEXT,
2594
2611
  DEFAULT_BREAKPOINTS,
2595
- DEFAULT_ROUNDED_ROOF,
2596
- DEFAULT_ROUNDED,
2597
2612
  CORNER_SHAPE_KEYWORDS,
2598
2613
  DEFAULT_CORNER_SCALE,
2599
2614
  DEFAULT_SUPERELLIPSE_SCALE,