rainbowindex 0.5.0 → 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.
@@ -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,