tailwind-to-style 4.0.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/animations/index.cjs +793 -469
- package/dist/animations/index.esm.js +793 -469
- package/dist/animations/index.esm.js.map +1 -1
- package/dist/className/index.cjs +793 -469
- package/dist/className/index.d.ts +41 -0
- package/dist/className/index.esm.js +793 -469
- package/dist/className/index.esm.js.map +1 -1
- package/dist/core/tws.cjs +322 -182
- package/dist/core/tws.esm.js +322 -182
- package/dist/core/tws.esm.js.map +1 -1
- package/dist/cx.cjs +1 -1
- package/dist/cx.esm.js +1 -1
- package/dist/index.cjs +882 -505
- package/dist/index.esm.js +882 -505
- package/dist/index.esm.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/react/index.cjs +882 -505
- package/dist/react/index.esm.js +882 -505
- package/dist/react/index.esm.js.map +1 -1
- package/dist/tokens/index.cjs +1 -1
- package/dist/tokens/index.esm.js +1 -1
- package/package.json +12 -4
- package/types/README.md +214 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* tailwind-to-style
|
|
2
|
+
* tailwind-to-style v5.0.0
|
|
3
3
|
* Zero-build runtime Tailwind CSS engine
|
|
4
4
|
*
|
|
5
5
|
* @author Bigetion
|
|
@@ -2147,6 +2147,182 @@ function getActiveCollector() {
|
|
|
2147
2147
|
return _activeCollector;
|
|
2148
2148
|
}
|
|
2149
2149
|
|
|
2150
|
+
/**
|
|
2151
|
+
* Shared Constants
|
|
2152
|
+
*
|
|
2153
|
+
* All constant values used across the library.
|
|
2154
|
+
* Extracted from monolithic index.js for better maintainability.
|
|
2155
|
+
*
|
|
2156
|
+
* @module shared/constants
|
|
2157
|
+
*/
|
|
2158
|
+
|
|
2159
|
+
// ============================================================================
|
|
2160
|
+
// Environment Detection
|
|
2161
|
+
// ============================================================================
|
|
2162
|
+
|
|
2163
|
+
/**
|
|
2164
|
+
* True when running in a browser environment (window & document available)
|
|
2165
|
+
*/
|
|
2166
|
+
const IS_BROWSER$1 = typeof window !== "undefined" && typeof document !== "undefined";
|
|
2167
|
+
|
|
2168
|
+
/**
|
|
2169
|
+
* Maximum number of entries in Set-based caches
|
|
2170
|
+
*/
|
|
2171
|
+
const MAX_SET_SIZE$1 = 10000;
|
|
2172
|
+
|
|
2173
|
+
// ============================================================================
|
|
2174
|
+
// Built-in Animation Keyframes
|
|
2175
|
+
// ============================================================================
|
|
2176
|
+
|
|
2177
|
+
/**
|
|
2178
|
+
* Mapping of animation names to their keyframe definitions
|
|
2179
|
+
*/
|
|
2180
|
+
const BUILTIN_KEYFRAMES = {
|
|
2181
|
+
spin: {
|
|
2182
|
+
"0%": {
|
|
2183
|
+
transform: "rotate(0deg)"
|
|
2184
|
+
},
|
|
2185
|
+
"100%": {
|
|
2186
|
+
transform: "rotate(360deg)"
|
|
2187
|
+
}
|
|
2188
|
+
},
|
|
2189
|
+
ping: {
|
|
2190
|
+
"75%, 100%": {
|
|
2191
|
+
transform: "scale(2)",
|
|
2192
|
+
opacity: "0"
|
|
2193
|
+
}
|
|
2194
|
+
},
|
|
2195
|
+
pulse: {
|
|
2196
|
+
"50%": {
|
|
2197
|
+
opacity: ".5"
|
|
2198
|
+
}
|
|
2199
|
+
},
|
|
2200
|
+
bounce: {
|
|
2201
|
+
"0%, 100%": {
|
|
2202
|
+
transform: "translateY(-25%)",
|
|
2203
|
+
animationTimingFunction: "cubic-bezier(0.8,0,1,1)"
|
|
2204
|
+
},
|
|
2205
|
+
"50%": {
|
|
2206
|
+
transform: "none",
|
|
2207
|
+
animationTimingFunction: "cubic-bezier(0,0,0.2,1)"
|
|
2208
|
+
}
|
|
2209
|
+
},
|
|
2210
|
+
fadeIn: {
|
|
2211
|
+
"0%": {
|
|
2212
|
+
opacity: "0"
|
|
2213
|
+
},
|
|
2214
|
+
"50%": {
|
|
2215
|
+
opacity: "1"
|
|
2216
|
+
},
|
|
2217
|
+
"100%": {
|
|
2218
|
+
opacity: "0"
|
|
2219
|
+
}
|
|
2220
|
+
},
|
|
2221
|
+
slideUp: {
|
|
2222
|
+
"0%": {
|
|
2223
|
+
transform: "translateY(20px)",
|
|
2224
|
+
opacity: "0"
|
|
2225
|
+
},
|
|
2226
|
+
"50%": {
|
|
2227
|
+
transform: "translateY(0)",
|
|
2228
|
+
opacity: "1"
|
|
2229
|
+
},
|
|
2230
|
+
"100%": {
|
|
2231
|
+
transform: "translateY(-20px)",
|
|
2232
|
+
opacity: "0"
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
};
|
|
2236
|
+
|
|
2237
|
+
/**
|
|
2238
|
+
* Opacity modifiers
|
|
2239
|
+
*/
|
|
2240
|
+
const OPACITY_MODIFIER_REGEX = /\/(\d+)$/;
|
|
2241
|
+
|
|
2242
|
+
/**
|
|
2243
|
+
* Opacity property patterns for substitution
|
|
2244
|
+
*/
|
|
2245
|
+
const OPACITY_PROP_REGEXES = {
|
|
2246
|
+
"--text-opacity": /--text-opacity\s*:\s*[\d.]+/gi,
|
|
2247
|
+
"--bg-opacity": /--bg-opacity\s*:\s*[\d.]+/gi,
|
|
2248
|
+
"--border-opacity": /--border-opacity\s*:\s*[\d.]+/gi,
|
|
2249
|
+
"--ring-opacity": /--ring-opacity\s*:\s*[\d.]+/gi,
|
|
2250
|
+
"--placeholder-opacity": /--placeholder-opacity\s*:\s*[\d.]+/gi,
|
|
2251
|
+
"--divide-opacity": /--divide-opacity\s*:\s*[\d.]+/gi
|
|
2252
|
+
};
|
|
2253
|
+
|
|
2254
|
+
/**
|
|
2255
|
+
* Bracket encoding/decoding
|
|
2256
|
+
*/
|
|
2257
|
+
const BRACKET_CONTENT_REGEX = /\[([^\]]+)\]/g;
|
|
2258
|
+
const OPENING_PAREN_REGEX = /\(/g;
|
|
2259
|
+
const CLOSING_PAREN_REGEX = /\)/g;
|
|
2260
|
+
const ENCODED_PAREN_OPEN_REGEX = /__P__/g;
|
|
2261
|
+
const ENCODED_PAREN_CLOSE_REGEX = /__C__/g;
|
|
2262
|
+
|
|
2263
|
+
/**
|
|
2264
|
+
* Animation detection
|
|
2265
|
+
*/
|
|
2266
|
+
const ANIMATION_NAME_REGEX = /animation(?:-name)?:\s*([a-zA-Z0-9-]+)/gi;
|
|
2267
|
+
|
|
2268
|
+
/**
|
|
2269
|
+
* Color property regex patterns (pre-compiled for each color property)
|
|
2270
|
+
* Used in processOpacityModifier for 50-100x performance improvement
|
|
2271
|
+
*/
|
|
2272
|
+
const COLOR_PROPERTIES$1 = ["color", "background-color", "border-color", "border-top-color", "border-right-color", "border-bottom-color", "border-left-color"];
|
|
2273
|
+
|
|
2274
|
+
/**
|
|
2275
|
+
* CSS property name conversion
|
|
2276
|
+
*/
|
|
2277
|
+
const UPPERCASE_LETTER_REGEX = /([A-Z])/g;
|
|
2278
|
+
|
|
2279
|
+
/**
|
|
2280
|
+
* Hash Utilities
|
|
2281
|
+
*
|
|
2282
|
+
* Fast hashing functions for string and object caching.
|
|
2283
|
+
* Extracted from monolithic index.js for reusability.
|
|
2284
|
+
*
|
|
2285
|
+
* @module shared/hash
|
|
2286
|
+
*/
|
|
2287
|
+
|
|
2288
|
+
/**
|
|
2289
|
+
* Fast string hash using FNV-1a algorithm.
|
|
2290
|
+
* Produces 32-bit hash values for cache keys.
|
|
2291
|
+
*
|
|
2292
|
+
* @param {string} str - String to hash
|
|
2293
|
+
* @returns {number} 32-bit hash
|
|
2294
|
+
*
|
|
2295
|
+
* @example
|
|
2296
|
+
* hashString('bg-blue-500') // → 2845719273
|
|
2297
|
+
* hashString('hover:bg-red-600') // → 3927461034
|
|
2298
|
+
*/
|
|
2299
|
+
function hashString$2(str) {
|
|
2300
|
+
let hash = 2166136261; // FNV offset basis
|
|
2301
|
+
for (let i = 0; i < str.length; i++) {
|
|
2302
|
+
hash ^= str.charCodeAt(i);
|
|
2303
|
+
// FNV prime: 16777619
|
|
2304
|
+
hash = hash * 16777619 >>> 0; // >>> 0 keeps it a 32-bit unsigned integer
|
|
2305
|
+
}
|
|
2306
|
+
return hash;
|
|
2307
|
+
}
|
|
2308
|
+
|
|
2309
|
+
/**
|
|
2310
|
+
* Generate a short hash for CSS class names.
|
|
2311
|
+
* Uses base36 encoding for compact, URL-safe identifiers.
|
|
2312
|
+
*
|
|
2313
|
+
* @param {string} str - Input string
|
|
2314
|
+
* @param {number} length - Desired hash length (default: 8)
|
|
2315
|
+
* @returns {string} Short hash string
|
|
2316
|
+
*
|
|
2317
|
+
* @example
|
|
2318
|
+
* getCssHash('bg-blue-500 p-4 rounded') // → 'x7k2m9n1'
|
|
2319
|
+
*/
|
|
2320
|
+
function getCssHash(str) {
|
|
2321
|
+
let length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 8;
|
|
2322
|
+
const hash = hashString$2(str);
|
|
2323
|
+
return hash.toString(36).substring(0, length);
|
|
2324
|
+
}
|
|
2325
|
+
|
|
2150
2326
|
/**
|
|
2151
2327
|
* Proper LRU (Least Recently Used) Cache implementation
|
|
2152
2328
|
* Efficiently manages memory by removing least recently used items
|
|
@@ -2173,49 +2349,496 @@ class LRUCache {
|
|
|
2173
2349
|
return value;
|
|
2174
2350
|
}
|
|
2175
2351
|
|
|
2176
|
-
/**
|
|
2177
|
-
* Set value in cache
|
|
2178
|
-
* Removes least recently used item if cache is full
|
|
2179
|
-
*/
|
|
2180
|
-
set(key, value) {
|
|
2181
|
-
// If key exists, delete it first to update position
|
|
2182
|
-
if (this.cache.has(key)) {
|
|
2183
|
-
this.cache.delete(key);
|
|
2184
|
-
} else if (this.cache.size >= this.maxSize) {
|
|
2185
|
-
// Remove least recently used (first item)
|
|
2186
|
-
const firstKey = this.cache.keys().next().value;
|
|
2187
|
-
this.cache.delete(firstKey);
|
|
2352
|
+
/**
|
|
2353
|
+
* Set value in cache
|
|
2354
|
+
* Removes least recently used item if cache is full
|
|
2355
|
+
*/
|
|
2356
|
+
set(key, value) {
|
|
2357
|
+
// If key exists, delete it first to update position
|
|
2358
|
+
if (this.cache.has(key)) {
|
|
2359
|
+
this.cache.delete(key);
|
|
2360
|
+
} else if (this.cache.size >= this.maxSize) {
|
|
2361
|
+
// Remove least recently used (first item)
|
|
2362
|
+
const firstKey = this.cache.keys().next().value;
|
|
2363
|
+
this.cache.delete(firstKey);
|
|
2364
|
+
}
|
|
2365
|
+
this.cache.set(key, value);
|
|
2366
|
+
}
|
|
2367
|
+
|
|
2368
|
+
/**
|
|
2369
|
+
* Check if key exists in cache
|
|
2370
|
+
*/
|
|
2371
|
+
has(key) {
|
|
2372
|
+
return this.cache.has(key);
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2375
|
+
/**
|
|
2376
|
+
* Clear all cache entries
|
|
2377
|
+
*/
|
|
2378
|
+
clear() {
|
|
2379
|
+
this.cache.clear();
|
|
2380
|
+
}
|
|
2381
|
+
|
|
2382
|
+
/**
|
|
2383
|
+
* Get current cache size
|
|
2384
|
+
*/
|
|
2385
|
+
get size() {
|
|
2386
|
+
return this.cache.size;
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2389
|
+
/**
|
|
2390
|
+
* Delete specific key
|
|
2391
|
+
*/
|
|
2392
|
+
delete(key) {
|
|
2393
|
+
return this.cache.delete(key);
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
|
|
2397
|
+
/**
|
|
2398
|
+
* Cache Management
|
|
2399
|
+
*
|
|
2400
|
+
* Global caches and cache utilities for performance optimization.
|
|
2401
|
+
* Uses LRU (Least Recently Used) strategy to prevent memory leaks.
|
|
2402
|
+
*
|
|
2403
|
+
* @module shared/cache
|
|
2404
|
+
*/
|
|
2405
|
+
|
|
2406
|
+
|
|
2407
|
+
/**
|
|
2408
|
+
* Cache for bracket value encoding
|
|
2409
|
+
* @type {LRUCache}
|
|
2410
|
+
*/
|
|
2411
|
+
const encodeBracketCache = new LRUCache(1000);
|
|
2412
|
+
|
|
2413
|
+
/**
|
|
2414
|
+
* Cache for bracket value decoding
|
|
2415
|
+
* @type {LRUCache}
|
|
2416
|
+
*/
|
|
2417
|
+
const decodeBracketCache = new LRUCache(1000);
|
|
2418
|
+
|
|
2419
|
+
/**
|
|
2420
|
+
* Set of injected CSS hashes (prevents duplicate injection)
|
|
2421
|
+
* @type {Set<string>}
|
|
2422
|
+
*/
|
|
2423
|
+
const injectedCssHashSet = new Set();
|
|
2424
|
+
|
|
2425
|
+
/**
|
|
2426
|
+
* Registry of sourceKey → cssBlock for smart slot-based replacement
|
|
2427
|
+
* Prevents stale CSS chunks from accumulating across HMR cycles
|
|
2428
|
+
* @type {Map<string, string>}
|
|
2429
|
+
*/
|
|
2430
|
+
const cssBlockRegistry = new Map();
|
|
2431
|
+
|
|
2432
|
+
/**
|
|
2433
|
+
* Evict old entries from a Set when size exceeds maxSize.
|
|
2434
|
+
*
|
|
2435
|
+
* @deprecated Use LRUCache instead - kept for backward compatibility
|
|
2436
|
+
* @param {Set|LRUCache} set - Set to evict from
|
|
2437
|
+
* @param {number} maxSize - Maximum size
|
|
2438
|
+
*/
|
|
2439
|
+
function evictSet(set) {
|
|
2440
|
+
let maxSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : MAX_SET_SIZE$1;
|
|
2441
|
+
if (set instanceof LRUCache) return; // LRUCache handles its own eviction
|
|
2442
|
+
if (set.size <= maxSize) return;
|
|
2443
|
+
const excess = set.size - maxSize;
|
|
2444
|
+
const iter = set.values();
|
|
2445
|
+
for (let i = 0; i < excess; i++) {
|
|
2446
|
+
set.delete(iter.next().value);
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
|
|
2450
|
+
/**
|
|
2451
|
+
* Generate minified CSS keyframes for animations.
|
|
2452
|
+
* Converts camelCase property names to kebab-case.
|
|
2453
|
+
*
|
|
2454
|
+
* @param {string[]} animationNames - Array of animation names to generate
|
|
2455
|
+
* @returns {string} Minified CSS @keyframes rules
|
|
2456
|
+
*
|
|
2457
|
+
* @example
|
|
2458
|
+
* generateMinifiedKeyframes(['spin', 'pulse'])
|
|
2459
|
+
* // → '@keyframes spin{0%{transform:rotate(0deg);}100%{transform:rotate(360deg);}}
|
|
2460
|
+
* // @keyframes pulse{50%{opacity:.5;}}'
|
|
2461
|
+
*
|
|
2462
|
+
* @example
|
|
2463
|
+
* generateMinifiedKeyframes(['fadeIn'])
|
|
2464
|
+
* // → '@keyframes fadeIn{0%{opacity:0;}50%{opacity:1;}100%{opacity:0;}}'
|
|
2465
|
+
*/
|
|
2466
|
+
function generateMinifiedKeyframes(animationNames) {
|
|
2467
|
+
let css = "";
|
|
2468
|
+
for (const name of animationNames) {
|
|
2469
|
+
const keyframe = BUILTIN_KEYFRAMES[name];
|
|
2470
|
+
if (!keyframe) continue;
|
|
2471
|
+
css += "@keyframes ".concat(name, "{");
|
|
2472
|
+
for (const _ref of Object.entries(keyframe)) {
|
|
2473
|
+
var _ref2 = _slicedToArray(_ref, 2);
|
|
2474
|
+
const percentage = _ref2[0];
|
|
2475
|
+
const styles = _ref2[1];
|
|
2476
|
+
css += "".concat(percentage, "{");
|
|
2477
|
+
for (const _ref3 of Object.entries(styles)) {
|
|
2478
|
+
var _ref4 = _slicedToArray(_ref3, 2);
|
|
2479
|
+
const prop = _ref4[0];
|
|
2480
|
+
const value = _ref4[1];
|
|
2481
|
+
const cssProp = prop.replace(UPPERCASE_LETTER_REGEX, "-$1").toLowerCase();
|
|
2482
|
+
css += "".concat(cssProp, ":").concat(value, ";");
|
|
2483
|
+
}
|
|
2484
|
+
css += "}";
|
|
2485
|
+
}
|
|
2486
|
+
css += "}";
|
|
2487
|
+
}
|
|
2488
|
+
return css;
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
/**
|
|
2492
|
+
* Opacity Modifier Processing
|
|
2493
|
+
*
|
|
2494
|
+
* Handles Tailwind opacity modifiers (e.g., bg-blue-500/50).
|
|
2495
|
+
* Converts color values to rgba/hsla with specified opacity.
|
|
2496
|
+
*
|
|
2497
|
+
* @module generator/opacity
|
|
2498
|
+
*/
|
|
2499
|
+
|
|
2500
|
+
|
|
2501
|
+
// Pre-compile regex patterns for each color property
|
|
2502
|
+
const COLOR_REGEX_PATTERNS$1 = new Map();
|
|
2503
|
+
for (const prop of COLOR_PROPERTIES$1) {
|
|
2504
|
+
const escapedProp = prop.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2505
|
+
COLOR_REGEX_PATTERNS$1.set(prop, {
|
|
2506
|
+
rgb: new RegExp("(".concat(escapedProp, "\\s*:\\s*)rgb\\((\\d+),\\s*(\\d+),\\s*(\\d+)\\)"), "gi"),
|
|
2507
|
+
rgba: new RegExp("(".concat(escapedProp, "\\s*:\\s*)rgba\\((\\d+),\\s*(\\d+),\\s*(\\d+),\\s*[\\d.]+\\)"), "gi"),
|
|
2508
|
+
hsl: new RegExp("(".concat(escapedProp, "\\s*:\\s*)hsl\\((\\d+),\\s*([\\d.]+%),\\s*([\\d.]+%)\\)"), "gi"),
|
|
2509
|
+
hsla: new RegExp("(".concat(escapedProp, "\\s*:\\s*)hsla\\((\\d+),\\s*([\\d.]+%),\\s*([\\d.]+%),\\s*[\\d.]+\\)"), "gi"),
|
|
2510
|
+
hex: new RegExp("(".concat(escapedProp, "\\s*:\\s*)(#[0-9a-fA-F]{3,6})"), "gi")
|
|
2511
|
+
});
|
|
2512
|
+
}
|
|
2513
|
+
|
|
2514
|
+
/**
|
|
2515
|
+
* Process opacity modifiers in Tailwind classes.
|
|
2516
|
+
*
|
|
2517
|
+
* Handles:
|
|
2518
|
+
* - Tailwind CSS custom properties (--text-opacity, --bg-opacity, etc.)
|
|
2519
|
+
* - Direct color values (rgb, rgba, hsl, hsla, hex)
|
|
2520
|
+
* - Converts colors to rgba/hsla with specified opacity
|
|
2521
|
+
*
|
|
2522
|
+
* @param {string} className - Tailwind class name (e.g., 'bg-blue-500/50')
|
|
2523
|
+
* @param {string} cssDeclaration - CSS declaration to modify
|
|
2524
|
+
* @returns {string} Modified CSS declaration with opacity applied
|
|
2525
|
+
*
|
|
2526
|
+
* @example
|
|
2527
|
+
* processOpacityModifier('bg-blue-500/50', 'background-color: rgb(59, 130, 246);')
|
|
2528
|
+
* // → 'background-color: rgba(59, 130, 246, 0.5);'
|
|
2529
|
+
*
|
|
2530
|
+
* @example
|
|
2531
|
+
* processOpacityModifier('text-red-600/75', 'color: #dc2626;')
|
|
2532
|
+
* // → 'color: rgba(220, 38, 38, 0.75);'
|
|
2533
|
+
*
|
|
2534
|
+
* @example
|
|
2535
|
+
* processOpacityModifier('bg-blue-500', 'background-color: rgb(59, 130, 246);')
|
|
2536
|
+
* // → 'background-color: rgb(59, 130, 246);' (no change - no opacity modifier)
|
|
2537
|
+
*/
|
|
2538
|
+
function processOpacityModifier(className, cssDeclaration) {
|
|
2539
|
+
const opacityMatch = OPACITY_MODIFIER_REGEX.exec(className);
|
|
2540
|
+
if (!opacityMatch) return cssDeclaration;
|
|
2541
|
+
const opacityValue = parseInt(opacityMatch[1], 10);
|
|
2542
|
+
if (opacityValue < 0 || opacityValue > 100) return cssDeclaration;
|
|
2543
|
+
const alphaValue = (opacityValue / 100).toString();
|
|
2544
|
+
|
|
2545
|
+
// Handle Tailwind's CSS custom property pattern
|
|
2546
|
+
let modifiedDeclaration = cssDeclaration;
|
|
2547
|
+
|
|
2548
|
+
// Replace opacity custom properties using pre-compiled regexes
|
|
2549
|
+
for (const prop in OPACITY_PROP_REGEXES) {
|
|
2550
|
+
const regex = OPACITY_PROP_REGEXES[prop];
|
|
2551
|
+
regex.lastIndex = 0; // Reset global regex
|
|
2552
|
+
modifiedDeclaration = modifiedDeclaration.replace(regex, "".concat(prop, ": ").concat(alphaValue));
|
|
2553
|
+
}
|
|
2554
|
+
|
|
2555
|
+
// Also handle direct color values using pre-compiled regex patterns
|
|
2556
|
+
for (const prop of COLOR_PROPERTIES$1) {
|
|
2557
|
+
const patterns = COLOR_REGEX_PATTERNS$1.get(prop);
|
|
2558
|
+
if (!patterns) continue;
|
|
2559
|
+
|
|
2560
|
+
// Reset all regex lastIndex for reuse
|
|
2561
|
+
patterns.rgb.lastIndex = 0;
|
|
2562
|
+
patterns.rgba.lastIndex = 0;
|
|
2563
|
+
patterns.hsl.lastIndex = 0;
|
|
2564
|
+
patterns.hsla.lastIndex = 0;
|
|
2565
|
+
patterns.hex.lastIndex = 0;
|
|
2566
|
+
|
|
2567
|
+
// Convert rgb to rgba with opacity
|
|
2568
|
+
modifiedDeclaration = modifiedDeclaration.replace(patterns.rgb, "$1rgba($2, $3, $4, ".concat(alphaValue, ")"));
|
|
2569
|
+
|
|
2570
|
+
// Update existing rgba opacity
|
|
2571
|
+
modifiedDeclaration = modifiedDeclaration.replace(patterns.rgba, "$1rgba($2, $3, $4, ".concat(alphaValue, ")"));
|
|
2572
|
+
|
|
2573
|
+
// Convert hsl to hsla with opacity
|
|
2574
|
+
modifiedDeclaration = modifiedDeclaration.replace(patterns.hsl, "$1hsla($2, $3, $4, ".concat(alphaValue, ")"));
|
|
2575
|
+
|
|
2576
|
+
// Update existing hsla opacity
|
|
2577
|
+
modifiedDeclaration = modifiedDeclaration.replace(patterns.hsla, "$1hsla($2, $3, $4, ".concat(alphaValue, ")"));
|
|
2578
|
+
|
|
2579
|
+
// Handle hex colors - convert to rgba
|
|
2580
|
+
modifiedDeclaration = modifiedDeclaration.replace(patterns.hex, (match, propPart, hexColor) => {
|
|
2581
|
+
// Convert hex to rgba
|
|
2582
|
+
const hex = hexColor.replace("#", "");
|
|
2583
|
+
let r, g, b;
|
|
2584
|
+
if (hex.length === 3) {
|
|
2585
|
+
r = parseInt(hex[0] + hex[0], 16);
|
|
2586
|
+
g = parseInt(hex[1] + hex[1], 16);
|
|
2587
|
+
b = parseInt(hex[2] + hex[2], 16);
|
|
2588
|
+
} else {
|
|
2589
|
+
r = parseInt(hex.substring(0, 2), 16);
|
|
2590
|
+
g = parseInt(hex.substring(2, 4), 16);
|
|
2591
|
+
b = parseInt(hex.substring(4, 6), 16);
|
|
2592
|
+
}
|
|
2593
|
+
return "".concat(propPart, "rgba(").concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(alphaValue, ")");
|
|
2594
|
+
});
|
|
2595
|
+
}
|
|
2596
|
+
return modifiedDeclaration;
|
|
2597
|
+
}
|
|
2598
|
+
|
|
2599
|
+
/**
|
|
2600
|
+
* Performance Monitoring Utilities
|
|
2601
|
+
*
|
|
2602
|
+
* Tracks and logs performance metrics for optimization analysis.
|
|
2603
|
+
*
|
|
2604
|
+
* @module utils/performanceMonitor
|
|
2605
|
+
*/
|
|
2606
|
+
|
|
2607
|
+
|
|
2608
|
+
/**
|
|
2609
|
+
* Performance monitoring system
|
|
2610
|
+
*
|
|
2611
|
+
* Provides start/end timing and automatic slow operation logging.
|
|
2612
|
+
*/
|
|
2613
|
+
const performanceMonitor$1 = {
|
|
2614
|
+
enabled: typeof performance !== "undefined",
|
|
2615
|
+
/**
|
|
2616
|
+
* Start performance measurement
|
|
2617
|
+
*
|
|
2618
|
+
* @param {string} label - Label for the measurement
|
|
2619
|
+
* @returns {Object|null} Marker object with label and start time
|
|
2620
|
+
*/
|
|
2621
|
+
start(label) {
|
|
2622
|
+
if (!this.enabled) return null;
|
|
2623
|
+
return {
|
|
2624
|
+
label,
|
|
2625
|
+
startTime: performance.now()
|
|
2626
|
+
};
|
|
2627
|
+
},
|
|
2628
|
+
/**
|
|
2629
|
+
* End performance measurement and log if slow
|
|
2630
|
+
*
|
|
2631
|
+
* @param {Object} marker - Marker from start()
|
|
2632
|
+
*/
|
|
2633
|
+
end(marker) {
|
|
2634
|
+
if (!this.enabled || !marker) return;
|
|
2635
|
+
const duration = performance.now() - marker.startTime;
|
|
2636
|
+
if (duration > 5) {
|
|
2637
|
+
// Only log if > 5ms
|
|
2638
|
+
logger.warn("Slow ".concat(marker.label, ": ").concat(duration.toFixed(2), "ms"));
|
|
2639
|
+
}
|
|
2640
|
+
},
|
|
2641
|
+
/**
|
|
2642
|
+
* Measure function execution time
|
|
2643
|
+
*
|
|
2644
|
+
* @param {Function} fn - Function to measure
|
|
2645
|
+
* @param {string} label - Label for measurement
|
|
2646
|
+
* @returns {*} Function result
|
|
2647
|
+
*/
|
|
2648
|
+
measure(fn, label) {
|
|
2649
|
+
const marker = this.start(label);
|
|
2650
|
+
try {
|
|
2651
|
+
const result = fn();
|
|
2652
|
+
this.end(marker);
|
|
2653
|
+
return result;
|
|
2654
|
+
} catch (error) {
|
|
2655
|
+
this.end(marker);
|
|
2656
|
+
throw error;
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2659
|
+
};
|
|
2660
|
+
|
|
2661
|
+
/**
|
|
2662
|
+
* DOM CSS Injector
|
|
2663
|
+
*
|
|
2664
|
+
* Handles automatic CSS injection into the DOM.
|
|
2665
|
+
* Supports SSR mode, HMR-friendly block registry, and hash-based deduplication.
|
|
2666
|
+
*
|
|
2667
|
+
* @module injector/dom
|
|
2668
|
+
*/
|
|
2669
|
+
|
|
2670
|
+
|
|
2671
|
+
/**
|
|
2672
|
+
* Rebuild the style tag from the CSS block registry.
|
|
2673
|
+
*
|
|
2674
|
+
* Used for slot-based updates where each twsx() call owns its own CSS block.
|
|
2675
|
+
* Rebuilds the entire style tag to avoid stale CSS from previous HMR cycles.
|
|
2676
|
+
*
|
|
2677
|
+
* @private
|
|
2678
|
+
*/
|
|
2679
|
+
function rebuildStyleTag$1() {
|
|
2680
|
+
let styleTag = document.getElementById("twsx-auto-style");
|
|
2681
|
+
if (!styleTag) {
|
|
2682
|
+
styleTag = document.createElement("style");
|
|
2683
|
+
styleTag.id = "twsx-auto-style";
|
|
2684
|
+
styleTag.setAttribute("data-twsx", "");
|
|
2685
|
+
document.head.appendChild(styleTag);
|
|
2686
|
+
}
|
|
2687
|
+
styleTag.textContent = [...cssBlockRegistry.values()].join("\n");
|
|
2688
|
+
}
|
|
2689
|
+
|
|
2690
|
+
/**
|
|
2691
|
+
* Automatically inject CSS into the DOM or collect for SSR.
|
|
2692
|
+
*
|
|
2693
|
+
* Supports three modes:
|
|
2694
|
+
* 1. SSR mode: Delegates to utils/ssr.js collector
|
|
2695
|
+
* 2. Slot-based mode (with sourceKey): HMR-friendly block registry
|
|
2696
|
+
* 3. Hash-based mode (no sourceKey): Legacy deduplication
|
|
2697
|
+
*
|
|
2698
|
+
* @param {string} cssString - CSS to inject
|
|
2699
|
+
* @param {string|null} sourceKey - Optional unique key for slot-based updates
|
|
2700
|
+
*
|
|
2701
|
+
* @example
|
|
2702
|
+
* // Slot-based (HMR-friendly)
|
|
2703
|
+
* autoInjectCss('.btn { color: blue; }', 'twsx-call-123');
|
|
2704
|
+
*
|
|
2705
|
+
* @example
|
|
2706
|
+
* // Hash-based (legacy)
|
|
2707
|
+
* autoInjectCss('.btn { color: blue; }');
|
|
2708
|
+
*
|
|
2709
|
+
* @example
|
|
2710
|
+
* // SSR mode (delegates to ssr.js)
|
|
2711
|
+
* startSSR();
|
|
2712
|
+
* autoInjectCss('.btn { color: blue; }');
|
|
2713
|
+
* const css = stopSSR();
|
|
2714
|
+
*/
|
|
2715
|
+
function autoInjectCss(cssString) {
|
|
2716
|
+
let sourceKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
2717
|
+
const marker = performanceMonitor$1.start("css:inject");
|
|
2718
|
+
try {
|
|
2719
|
+
// SSR mode: collect CSS strings instead of DOM injection. Delegates to
|
|
2720
|
+
// the shared collector in ./utils/ssr.js so both the legacy
|
|
2721
|
+
// startSSR()/stopSSR() pair and the modern createSSRCollector() actually
|
|
2722
|
+
// receive the CSS generated by tw()/twsx().
|
|
2723
|
+
if (isSSRCollecting()) {
|
|
2724
|
+
collectSSRCSS(cssString);
|
|
2725
|
+
performanceMonitor$1.end(marker);
|
|
2726
|
+
return;
|
|
2727
|
+
}
|
|
2728
|
+
if (IS_BROWSER$1) {
|
|
2729
|
+
if (sourceKey) {
|
|
2730
|
+
// Slot-based update: each unique twsx(obj) call owns its own CSS block.
|
|
2731
|
+
// When styles change (new content, same logical call site via cacheKey)
|
|
2732
|
+
// the old slot is replaced and the style tag is fully rebuilt, so no
|
|
2733
|
+
// stale rules from previous HMR cycles can pile up.
|
|
2734
|
+
const existing = cssBlockRegistry.get(sourceKey);
|
|
2735
|
+
if (existing === cssString) {
|
|
2736
|
+
// Identical content – nothing to do.
|
|
2737
|
+
performanceMonitor$1.end(marker);
|
|
2738
|
+
return;
|
|
2739
|
+
}
|
|
2740
|
+
cssBlockRegistry.set(sourceKey, cssString);
|
|
2741
|
+
rebuildStyleTag$1();
|
|
2742
|
+
if (cssBlockRegistry.size % 10 === 0) {
|
|
2743
|
+
logger.debug("CSS registry stats: ".concat(cssBlockRegistry.size, " blocks registered"));
|
|
2744
|
+
}
|
|
2745
|
+
performanceMonitor$1.end(marker);
|
|
2746
|
+
return;
|
|
2747
|
+
}
|
|
2748
|
+
|
|
2749
|
+
// Fallback path (e.g. direct autoInjectCss calls without a sourceKey):
|
|
2750
|
+
// keep the original hash-based dedup + append behaviour.
|
|
2751
|
+
const cssHash = getCssHash(cssString);
|
|
2752
|
+
if (injectedCssHashSet.has(cssHash)) {
|
|
2753
|
+
performanceMonitor$1.end(marker);
|
|
2754
|
+
return;
|
|
2755
|
+
}
|
|
2756
|
+
injectedCssHashSet.add(cssHash);
|
|
2757
|
+
evictSet(injectedCssHashSet);
|
|
2758
|
+
let styleTag = document.getElementById("twsx-auto-style");
|
|
2759
|
+
if (!styleTag) {
|
|
2760
|
+
styleTag = document.createElement("style");
|
|
2761
|
+
styleTag.id = "twsx-auto-style";
|
|
2762
|
+
styleTag.setAttribute("data-twsx", "");
|
|
2763
|
+
document.head.appendChild(styleTag);
|
|
2764
|
+
}
|
|
2765
|
+
|
|
2766
|
+
// Append CSS to style tag using textContent for reliability
|
|
2767
|
+
// Note: insertRule + textContent mixing destroys CSSOM rules,
|
|
2768
|
+
// so we use textContent exclusively for consistent behavior
|
|
2769
|
+
// with @keyframes, @media, and other nested CSS blocks.
|
|
2770
|
+
styleTag.textContent += "\n".concat(cssString);
|
|
2771
|
+
|
|
2772
|
+
// Log injection stats periodically
|
|
2773
|
+
if (injectedCssHashSet.size % 10 === 0) {
|
|
2774
|
+
logger.debug("CSS injection stats: ".concat(injectedCssHashSet.size, " unique stylesheets injected"));
|
|
2775
|
+
}
|
|
2188
2776
|
}
|
|
2189
|
-
|
|
2777
|
+
performanceMonitor$1.end(marker);
|
|
2778
|
+
} catch (error) {
|
|
2779
|
+
performanceMonitor$1.end(marker);
|
|
2780
|
+
logger.error("Error injecting CSS:", error);
|
|
2190
2781
|
}
|
|
2782
|
+
}
|
|
2191
2783
|
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2784
|
+
/**
|
|
2785
|
+
* Bracket Value Encoding/Decoding
|
|
2786
|
+
*
|
|
2787
|
+
* Handles encoding and decoding of bracket values in Tailwind classes.
|
|
2788
|
+
* Example: bg-[rgb(255,0,0)] → bg-[rgb__P__255%2C0%2C0__C__]
|
|
2789
|
+
*
|
|
2790
|
+
* @module parser/bracket
|
|
2791
|
+
*/
|
|
2198
2792
|
|
|
2199
|
-
/**
|
|
2200
|
-
* Clear all cache entries
|
|
2201
|
-
*/
|
|
2202
|
-
clear() {
|
|
2203
|
-
this.cache.clear();
|
|
2204
|
-
}
|
|
2205
2793
|
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2794
|
+
/**
|
|
2795
|
+
* Encode bracket values to prevent parsing issues.
|
|
2796
|
+
* Encodes parentheses within brackets to special markers.
|
|
2797
|
+
*
|
|
2798
|
+
* @param {string} input - Class string with brackets
|
|
2799
|
+
* @returns {string} Encoded string
|
|
2800
|
+
*
|
|
2801
|
+
* @example
|
|
2802
|
+
* encodeBracketValues('bg-[rgb(255,0,0)]')
|
|
2803
|
+
* // → 'bg-[rgb__P__255%2C0%2C0__C__]'
|
|
2804
|
+
*
|
|
2805
|
+
* @example
|
|
2806
|
+
* encodeBracketValues('w-[calc(100%-20px)]')
|
|
2807
|
+
* // → 'w-[calc__P__100%25-20px__C__]'
|
|
2808
|
+
*/
|
|
2809
|
+
function encodeBracketValues(input) {
|
|
2810
|
+
if (!input) return input;
|
|
2811
|
+
if (encodeBracketCache.has(input)) return encodeBracketCache.get(input);
|
|
2812
|
+
BRACKET_CONTENT_REGEX.lastIndex = 0; // Reset global regex
|
|
2813
|
+
const result = input.replace(BRACKET_CONTENT_REGEX, (_, content) => {
|
|
2814
|
+
const encoded = encodeURIComponent(content).replace(OPENING_PAREN_REGEX, "__P__").replace(CLOSING_PAREN_REGEX, "__C__");
|
|
2815
|
+
return "[".concat(encoded, "]");
|
|
2816
|
+
});
|
|
2817
|
+
encodeBracketCache.set(input, result);
|
|
2818
|
+
return result;
|
|
2819
|
+
}
|
|
2212
2820
|
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2821
|
+
/**
|
|
2822
|
+
* Decode previously encoded bracket values.
|
|
2823
|
+
* Reverses the encoding done by encodeBracketValues().
|
|
2824
|
+
*
|
|
2825
|
+
* @param {string} input - Encoded class string
|
|
2826
|
+
* @returns {string} Decoded string
|
|
2827
|
+
*
|
|
2828
|
+
* @example
|
|
2829
|
+
* decodeBracketValues('bg-[rgb__P__255%2C0%2C0__C__]')
|
|
2830
|
+
* // → 'bg-[rgb(255,0,0)]'
|
|
2831
|
+
*
|
|
2832
|
+
* @example
|
|
2833
|
+
* decodeBracketValues('w-[calc__P__100%25-20px__C__]')
|
|
2834
|
+
* // → 'w-[calc(100%-20px)]'
|
|
2835
|
+
*/
|
|
2836
|
+
function decodeBracketValues(input) {
|
|
2837
|
+
if (!input) return input;
|
|
2838
|
+
if (decodeBracketCache.has(input)) return decodeBracketCache.get(input);
|
|
2839
|
+
const result = decodeURIComponent(input).replace(ENCODED_PAREN_OPEN_REGEX, "(").replace(ENCODED_PAREN_CLOSE_REGEX, ")");
|
|
2840
|
+
decodeBracketCache.set(input, result);
|
|
2841
|
+
return result;
|
|
2219
2842
|
}
|
|
2220
2843
|
|
|
2221
2844
|
function generator$2S() {
|
|
@@ -5954,220 +6577,94 @@ const patterns = _objectSpread2(_objectSpread2({}, transition), fontFamily);
|
|
|
5954
6577
|
* // Arrays (nested)
|
|
5955
6578
|
* cx(['p-4', 'bg-white'], isActive && ['ring-2', 'ring-blue-500'])
|
|
5956
6579
|
* // → 'p-4 bg-white ring-2 ring-blue-500'
|
|
5957
|
-
*
|
|
5958
|
-
* @example
|
|
5959
|
-
* // Mixed
|
|
5960
|
-
* cx(
|
|
5961
|
-
* 'base-class',
|
|
5962
|
-
* condition && 'conditional-class',
|
|
5963
|
-
* { 'object-class': true, 'ignored-class': false },
|
|
5964
|
-
* ['array-class-1', 'array-class-2']
|
|
5965
|
-
* )
|
|
5966
|
-
*/
|
|
5967
|
-
function cx() {
|
|
5968
|
-
const classes = [];
|
|
5969
|
-
for (let i = 0; i < arguments.length; i++) {
|
|
5970
|
-
const arg = i < 0 || arguments.length <= i ? undefined : arguments[i];
|
|
5971
|
-
|
|
5972
|
-
// Skip falsy values
|
|
5973
|
-
if (!arg) continue;
|
|
5974
|
-
const type = typeof arg;
|
|
5975
|
-
if (type === 'string') {
|
|
5976
|
-
classes.push(arg);
|
|
5977
|
-
} else if (Array.isArray(arg)) {
|
|
5978
|
-
// Recursively process arrays
|
|
5979
|
-
const inner = cx(...arg);
|
|
5980
|
-
if (inner) classes.push(inner);
|
|
5981
|
-
} else if (type === 'object') {
|
|
5982
|
-
// Object: keys are class names, values are conditions
|
|
5983
|
-
const keys = Object.keys(arg);
|
|
5984
|
-
for (let j = 0; j < keys.length; j++) {
|
|
5985
|
-
if (arg[keys[j]]) {
|
|
5986
|
-
classes.push(keys[j]);
|
|
5987
|
-
}
|
|
5988
|
-
}
|
|
5989
|
-
}
|
|
5990
|
-
}
|
|
5991
|
-
return classes.join(' ');
|
|
5992
|
-
}
|
|
5993
|
-
|
|
5994
|
-
/**
|
|
5995
|
-
* Create a cx function bound with base classes.
|
|
5996
|
-
* Useful for component-level class composition.
|
|
5997
|
-
*
|
|
5998
|
-
* @param {...(string|Object|Array)} baseArgs - Base class arguments always included
|
|
5999
|
-
* @returns {Function} A cx function pre-filled with base classes
|
|
6000
|
-
*
|
|
6001
|
-
* @example
|
|
6002
|
-
* const btnClasses = cx.with('px-4 py-2 rounded font-medium transition-colors')
|
|
6003
|
-
*
|
|
6004
|
-
* btnClasses('bg-blue-500 text-white')
|
|
6005
|
-
* // → 'px-4 py-2 rounded font-medium transition-colors bg-blue-500 text-white'
|
|
6006
|
-
*
|
|
6007
|
-
* btnClasses({ 'opacity-50 cursor-not-allowed': isDisabled })
|
|
6008
|
-
* // → 'px-4 py-2 rounded font-medium transition-colors opacity-50 cursor-not-allowed'
|
|
6009
|
-
*/
|
|
6010
|
-
cx.with = function () {
|
|
6011
|
-
for (var _len = arguments.length, baseArgs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
6012
|
-
baseArgs[_key] = arguments[_key];
|
|
6013
|
-
}
|
|
6014
|
-
return function () {
|
|
6015
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
6016
|
-
args[_key2] = arguments[_key2];
|
|
6017
|
-
}
|
|
6018
|
-
return cx(...baseArgs, ...args);
|
|
6019
|
-
};
|
|
6020
|
-
};
|
|
6021
|
-
|
|
6022
|
-
// ============================================================================
|
|
6023
|
-
// SSR (Server-Side Rendering) Support
|
|
6024
|
-
// Detect environment once at module load for zero-cost runtime checks
|
|
6025
|
-
// ============================================================================
|
|
6026
|
-
const IS_BROWSER$1 = typeof window !== "undefined" && typeof document !== "undefined";
|
|
6027
|
-
const MAX_CACHE_SIZE$1 = 5000;
|
|
6028
|
-
const MAX_SET_SIZE = 10000;
|
|
6029
|
-
|
|
6030
|
-
// Global registry to track injected keyframes (prevents duplication) - now with LRU
|
|
6031
|
-
const _injectedKeyframes = new LRUCache(MAX_SET_SIZE);
|
|
6032
|
-
|
|
6033
|
-
// Global LRU cache instances (true LRU, not FIFO)
|
|
6034
|
-
const _twsxInputCache = new LRUCache(MAX_CACHE_SIZE$1);
|
|
6035
|
-
|
|
6036
|
-
// WeakMap for object identity-based caching (fast lookup for repeated objects)
|
|
6037
|
-
const _objectIdentityCache = new WeakMap();
|
|
6038
|
-
|
|
6039
|
-
/** @deprecated Use LRUCache instead - kept for backward compatibility */
|
|
6040
|
-
function evictSet(set) {
|
|
6041
|
-
let maxSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : MAX_SET_SIZE;
|
|
6042
|
-
if (set instanceof LRUCache) return; // LRUCache handles its own eviction
|
|
6043
|
-
if (set.size <= maxSize) return;
|
|
6044
|
-
const excess = set.size - maxSize;
|
|
6045
|
-
const iter = set.values();
|
|
6046
|
-
for (let i = 0; i < excess; i++) {
|
|
6047
|
-
set.delete(iter.next().value);
|
|
6048
|
-
}
|
|
6049
|
-
}
|
|
6050
|
-
|
|
6051
|
-
// Mapping of animation names to their keyframe definitions
|
|
6052
|
-
const BUILTIN_KEYFRAMES = {
|
|
6053
|
-
spin: {
|
|
6054
|
-
"0%": {
|
|
6055
|
-
transform: "rotate(0deg)"
|
|
6056
|
-
},
|
|
6057
|
-
"100%": {
|
|
6058
|
-
transform: "rotate(360deg)"
|
|
6059
|
-
}
|
|
6060
|
-
},
|
|
6061
|
-
ping: {
|
|
6062
|
-
"75%, 100%": {
|
|
6063
|
-
transform: "scale(2)",
|
|
6064
|
-
opacity: "0"
|
|
6065
|
-
}
|
|
6066
|
-
},
|
|
6067
|
-
pulse: {
|
|
6068
|
-
"50%": {
|
|
6069
|
-
opacity: ".5"
|
|
6070
|
-
}
|
|
6071
|
-
},
|
|
6072
|
-
bounce: {
|
|
6073
|
-
"0%, 100%": {
|
|
6074
|
-
transform: "translateY(-25%)",
|
|
6075
|
-
animationTimingFunction: "cubic-bezier(0.8,0,1,1)"
|
|
6076
|
-
},
|
|
6077
|
-
"50%": {
|
|
6078
|
-
transform: "none",
|
|
6079
|
-
animationTimingFunction: "cubic-bezier(0,0,0.2,1)"
|
|
6080
|
-
}
|
|
6081
|
-
},
|
|
6082
|
-
fadeIn: {
|
|
6083
|
-
"0%": {
|
|
6084
|
-
opacity: "0"
|
|
6085
|
-
},
|
|
6086
|
-
"50%": {
|
|
6087
|
-
opacity: "1"
|
|
6088
|
-
},
|
|
6089
|
-
"100%": {
|
|
6090
|
-
opacity: "0"
|
|
6091
|
-
}
|
|
6092
|
-
},
|
|
6093
|
-
slideUp: {
|
|
6094
|
-
"0%": {
|
|
6095
|
-
transform: "translateY(20px)",
|
|
6096
|
-
opacity: "0"
|
|
6097
|
-
},
|
|
6098
|
-
"50%": {
|
|
6099
|
-
transform: "translateY(0)",
|
|
6100
|
-
opacity: "1"
|
|
6101
|
-
},
|
|
6102
|
-
"100%": {
|
|
6103
|
-
transform: "translateY(-20px)",
|
|
6104
|
-
opacity: "0"
|
|
6105
|
-
}
|
|
6106
|
-
}
|
|
6107
|
-
};
|
|
6108
|
-
|
|
6109
|
-
// Generate minified keyframes CSS
|
|
6110
|
-
function generateMinifiedKeyframes(animationNames) {
|
|
6111
|
-
let css = "";
|
|
6112
|
-
for (const name of animationNames) {
|
|
6113
|
-
const keyframe = BUILTIN_KEYFRAMES[name];
|
|
6114
|
-
if (!keyframe) continue;
|
|
6115
|
-
css += "@keyframes ".concat(name, "{");
|
|
6116
|
-
for (const _ref of Object.entries(keyframe)) {
|
|
6117
|
-
var _ref2 = _slicedToArray(_ref, 2);
|
|
6118
|
-
const percentage = _ref2[0];
|
|
6119
|
-
const styles = _ref2[1];
|
|
6120
|
-
css += "".concat(percentage, "{");
|
|
6121
|
-
for (const _ref3 of Object.entries(styles)) {
|
|
6122
|
-
var _ref4 = _slicedToArray(_ref3, 2);
|
|
6123
|
-
const prop = _ref4[0];
|
|
6124
|
-
const value = _ref4[1];
|
|
6125
|
-
const cssProp = prop.replace(UPPERCASE_LETTER_REGEX, "-$1").toLowerCase();
|
|
6126
|
-
css += "".concat(cssProp, ":").concat(value, ";");
|
|
6580
|
+
*
|
|
6581
|
+
* @example
|
|
6582
|
+
* // Mixed
|
|
6583
|
+
* cx(
|
|
6584
|
+
* 'base-class',
|
|
6585
|
+
* condition && 'conditional-class',
|
|
6586
|
+
* { 'object-class': true, 'ignored-class': false },
|
|
6587
|
+
* ['array-class-1', 'array-class-2']
|
|
6588
|
+
* )
|
|
6589
|
+
*/
|
|
6590
|
+
function cx() {
|
|
6591
|
+
const classes = [];
|
|
6592
|
+
for (let i = 0; i < arguments.length; i++) {
|
|
6593
|
+
const arg = i < 0 || arguments.length <= i ? undefined : arguments[i];
|
|
6594
|
+
|
|
6595
|
+
// Skip falsy values
|
|
6596
|
+
if (!arg) continue;
|
|
6597
|
+
const type = typeof arg;
|
|
6598
|
+
if (type === 'string') {
|
|
6599
|
+
classes.push(arg);
|
|
6600
|
+
} else if (Array.isArray(arg)) {
|
|
6601
|
+
// Recursively process arrays
|
|
6602
|
+
const inner = cx(...arg);
|
|
6603
|
+
if (inner) classes.push(inner);
|
|
6604
|
+
} else if (type === 'object') {
|
|
6605
|
+
// Object: keys are class names, values are conditions
|
|
6606
|
+
const keys = Object.keys(arg);
|
|
6607
|
+
for (let j = 0; j < keys.length; j++) {
|
|
6608
|
+
if (arg[keys[j]]) {
|
|
6609
|
+
classes.push(keys[j]);
|
|
6610
|
+
}
|
|
6127
6611
|
}
|
|
6128
|
-
css += "}";
|
|
6129
6612
|
}
|
|
6130
|
-
css += "}";
|
|
6131
6613
|
}
|
|
6132
|
-
return
|
|
6614
|
+
return classes.join(' ');
|
|
6133
6615
|
}
|
|
6134
6616
|
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6617
|
+
/**
|
|
6618
|
+
* Create a cx function bound with base classes.
|
|
6619
|
+
* Useful for component-level class composition.
|
|
6620
|
+
*
|
|
6621
|
+
* @param {...(string|Object|Array)} baseArgs - Base class arguments always included
|
|
6622
|
+
* @returns {Function} A cx function pre-filled with base classes
|
|
6623
|
+
*
|
|
6624
|
+
* @example
|
|
6625
|
+
* const btnClasses = cx.with('px-4 py-2 rounded font-medium transition-colors')
|
|
6626
|
+
*
|
|
6627
|
+
* btnClasses('bg-blue-500 text-white')
|
|
6628
|
+
* // → 'px-4 py-2 rounded font-medium transition-colors bg-blue-500 text-white'
|
|
6629
|
+
*
|
|
6630
|
+
* btnClasses({ 'opacity-50 cursor-not-allowed': isDisabled })
|
|
6631
|
+
* // → 'px-4 py-2 rounded font-medium transition-colors opacity-50 cursor-not-allowed'
|
|
6632
|
+
*/
|
|
6633
|
+
cx.with = function () {
|
|
6634
|
+
for (var _len = arguments.length, baseArgs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
6635
|
+
baseArgs[_key] = arguments[_key];
|
|
6636
|
+
}
|
|
6637
|
+
return function () {
|
|
6638
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
6639
|
+
args[_key2] = arguments[_key2];
|
|
6640
|
+
}
|
|
6641
|
+
return cx(...baseArgs, ...args);
|
|
6642
|
+
};
|
|
6148
6643
|
};
|
|
6149
6644
|
|
|
6645
|
+
const MAX_CACHE_SIZE$1 = 5000;
|
|
6646
|
+
const MAX_SET_SIZE = 10000;
|
|
6647
|
+
|
|
6648
|
+
// Global registry to track injected keyframes (prevents duplication) - now with LRU
|
|
6649
|
+
const _injectedKeyframes = new LRUCache(MAX_SET_SIZE);
|
|
6650
|
+
|
|
6651
|
+
// Global LRU cache instances (true LRU, not FIFO)
|
|
6652
|
+
const _twsxInputCache = new LRUCache(MAX_CACHE_SIZE$1);
|
|
6653
|
+
|
|
6654
|
+
// WeakMap for object identity-based caching (fast lookup for repeated objects)
|
|
6655
|
+
const _objectIdentityCache = new WeakMap();
|
|
6656
|
+
|
|
6150
6657
|
// CSS parsing
|
|
6151
6658
|
const CSS_CLASS_REGEX = /([a-zA-Z0-9\-_\\/.]+)\s*{\s*([^}]+)\s*}/g;
|
|
6152
6659
|
const DOUBLE_BACKSLASH_REGEX = /\\\\/g;
|
|
6153
6660
|
const LEADING_UNDERSCORE_REGEX = /^_/;
|
|
6154
6661
|
const MULTIPLE_SPACES_REGEX = /\s+/g;
|
|
6155
6662
|
|
|
6156
|
-
// Bracket encoding/decoding
|
|
6157
|
-
const BRACKET_CONTENT_REGEX = /\[([^\]]+)\]/g;
|
|
6158
|
-
const OPENING_PAREN_REGEX = /\(/g;
|
|
6159
|
-
const CLOSING_PAREN_REGEX = /\)/g;
|
|
6160
|
-
const ENCODED_PAREN_OPEN_REGEX = /__P__/g;
|
|
6161
|
-
const ENCODED_PAREN_CLOSE_REGEX = /__C__/g;
|
|
6162
|
-
|
|
6163
6663
|
// Variant expansion
|
|
6164
6664
|
const DIRECTIVE_GROUP_REGEX = /(\w+)\(([^()]+)\)/g;
|
|
6165
6665
|
const VARIANT_GROUP_REGEX = /(\w+):\(([^()]+(?:\((?:[^()]+)\))?[^()]*)\)/g;
|
|
6166
6666
|
const WHITESPACE_SPLIT_REGEX = /\s+/;
|
|
6167
6667
|
const VARIANT_COLON_SPLIT_REGEX = /:/;
|
|
6168
|
-
|
|
6169
|
-
// Animation detection
|
|
6170
|
-
const ANIMATION_NAME_REGEX = /animation(?:-name)?:\s*([a-zA-Z0-9-]+)/gi;
|
|
6171
6668
|
const CUSTOM_VALUE_FULL_REGEX = /^(.+?)\[(.+)\]$/;
|
|
6172
6669
|
|
|
6173
6670
|
// Selector variants
|
|
@@ -6192,9 +6689,6 @@ for (const prop of COLOR_PROPERTIES) {
|
|
|
6192
6689
|
});
|
|
6193
6690
|
}
|
|
6194
6691
|
|
|
6195
|
-
// CSS property name conversion
|
|
6196
|
-
const UPPERCASE_LETTER_REGEX = /([A-Z])/g;
|
|
6197
|
-
|
|
6198
6692
|
// Escape characters
|
|
6199
6693
|
const ESCAPE_SLASH_REGEX = /\//g;
|
|
6200
6694
|
const ESCAPE_DOT_REGEX = /\./g;
|
|
@@ -6398,6 +6892,14 @@ function parseCustomClassWithPatterns(className) {
|
|
|
6398
6892
|
return null;
|
|
6399
6893
|
}
|
|
6400
6894
|
|
|
6895
|
+
/**
|
|
6896
|
+
* Resolve all CSS custom properties (var) in a CSS string and output only clear CSS (no custom property)
|
|
6897
|
+
* Optimized with for loops and indexOf for 2-3x better performance
|
|
6898
|
+
* @param {string} cssString
|
|
6899
|
+
* @returns {string} e.g. 'color: rgba(255,255,255,1); background: #fff;'
|
|
6900
|
+
*/
|
|
6901
|
+
// NOTE: resolveCssToClearCss now imported from ./generator/css-string.js
|
|
6902
|
+
|
|
6401
6903
|
// Cache for getConfigOptions - use LRU cache
|
|
6402
6904
|
const configOptionsCache = new LRUCache(500);
|
|
6403
6905
|
function generateTailwindCssString() {
|
|
@@ -6487,27 +6989,9 @@ const selectorVariants = {
|
|
|
6487
6989
|
number: arg => "> :nth-child(".concat(arg, ")")
|
|
6488
6990
|
};
|
|
6489
6991
|
|
|
6490
|
-
//
|
|
6491
|
-
|
|
6492
|
-
|
|
6493
|
-
if (!input) return input;
|
|
6494
|
-
if (encodeBracketCache.has(input)) return encodeBracketCache.get(input);
|
|
6495
|
-
BRACKET_CONTENT_REGEX.lastIndex = 0; // Reset global regex
|
|
6496
|
-
const result = input.replace(BRACKET_CONTENT_REGEX, (_, content) => {
|
|
6497
|
-
const encoded = encodeURIComponent(content).replace(OPENING_PAREN_REGEX, "__P__").replace(CLOSING_PAREN_REGEX, "__C__");
|
|
6498
|
-
return "[".concat(encoded, "]");
|
|
6499
|
-
});
|
|
6500
|
-
encodeBracketCache.set(input, result);
|
|
6501
|
-
return result;
|
|
6502
|
-
}
|
|
6503
|
-
const decodeBracketCache = new LRUCache(1000);
|
|
6504
|
-
function decodeBracketValues(input) {
|
|
6505
|
-
if (!input) return input;
|
|
6506
|
-
if (decodeBracketCache.has(input)) return decodeBracketCache.get(input);
|
|
6507
|
-
const result = decodeURIComponent(input).replace(ENCODED_PAREN_OPEN_REGEX, "(").replace(ENCODED_PAREN_CLOSE_REGEX, ")");
|
|
6508
|
-
decodeBracketCache.set(input, result);
|
|
6509
|
-
return result;
|
|
6510
|
-
}
|
|
6992
|
+
// NOTE: encodeBracketValues and decodeBracketValues now imported from ./parser/bracket.js
|
|
6993
|
+
// NOTE: encodeBracketCache and decodeBracketCache are in ./parser/bracket.js
|
|
6994
|
+
|
|
6511
6995
|
function replaceSelector(selector) {
|
|
6512
6996
|
SELECTOR_VARIANT_REGEX.lastIndex = 0; // Reset global regex
|
|
6513
6997
|
return selector.replace(SELECTOR_VARIANT_REGEX, (_, raw) => {
|
|
@@ -6545,73 +7029,6 @@ function resolveVariants(selector, variants) {
|
|
|
6545
7029
|
};
|
|
6546
7030
|
}
|
|
6547
7031
|
|
|
6548
|
-
/**
|
|
6549
|
-
* Process opacity modifier from class name (e.g., text-red-500/50 -> 50% opacity)
|
|
6550
|
-
* @param {string} className - Class name with potential opacity modifier
|
|
6551
|
-
* @param {string} cssDeclaration - CSS declaration to modify
|
|
6552
|
-
* @returns {string} Modified CSS declaration with opacity applied
|
|
6553
|
-
*/
|
|
6554
|
-
function processOpacityModifier(className, cssDeclaration) {
|
|
6555
|
-
const opacityMatch = OPACITY_MODIFIER_REGEX.exec(className);
|
|
6556
|
-
if (!opacityMatch) return cssDeclaration;
|
|
6557
|
-
const opacityValue = parseInt(opacityMatch[1], 10);
|
|
6558
|
-
if (opacityValue < 0 || opacityValue > 100) return cssDeclaration;
|
|
6559
|
-
const alphaValue = (opacityValue / 100).toString();
|
|
6560
|
-
|
|
6561
|
-
// Handle Tailwind's CSS custom property pattern
|
|
6562
|
-
let modifiedDeclaration = cssDeclaration;
|
|
6563
|
-
|
|
6564
|
-
// Replace opacity custom properties using pre-compiled regexes
|
|
6565
|
-
for (const prop in OPACITY_PROP_REGEXES) {
|
|
6566
|
-
const regex = OPACITY_PROP_REGEXES[prop];
|
|
6567
|
-
regex.lastIndex = 0; // Reset global regex
|
|
6568
|
-
modifiedDeclaration = modifiedDeclaration.replace(regex, "".concat(prop, ": ").concat(alphaValue));
|
|
6569
|
-
}
|
|
6570
|
-
|
|
6571
|
-
// Also handle direct color values using pre-compiled regex patterns
|
|
6572
|
-
for (const prop of COLOR_PROPERTIES) {
|
|
6573
|
-
const patterns = COLOR_REGEX_PATTERNS.get(prop);
|
|
6574
|
-
if (!patterns) continue;
|
|
6575
|
-
|
|
6576
|
-
// Reset all regex lastIndex for reuse
|
|
6577
|
-
patterns.rgb.lastIndex = 0;
|
|
6578
|
-
patterns.rgba.lastIndex = 0;
|
|
6579
|
-
patterns.hsl.lastIndex = 0;
|
|
6580
|
-
patterns.hsla.lastIndex = 0;
|
|
6581
|
-
patterns.hex.lastIndex = 0;
|
|
6582
|
-
|
|
6583
|
-
// Convert rgb to rgba with opacity
|
|
6584
|
-
modifiedDeclaration = modifiedDeclaration.replace(patterns.rgb, "$1rgba($2, $3, $4, ".concat(alphaValue, ")"));
|
|
6585
|
-
|
|
6586
|
-
// Update existing rgba opacity
|
|
6587
|
-
modifiedDeclaration = modifiedDeclaration.replace(patterns.rgba, "$1rgba($2, $3, $4, ".concat(alphaValue, ")"));
|
|
6588
|
-
|
|
6589
|
-
// Convert hsl to hsla with opacity
|
|
6590
|
-
modifiedDeclaration = modifiedDeclaration.replace(patterns.hsl, "$1hsla($2, $3, $4, ".concat(alphaValue, ")"));
|
|
6591
|
-
|
|
6592
|
-
// Update existing hsla opacity
|
|
6593
|
-
modifiedDeclaration = modifiedDeclaration.replace(patterns.hsla, "$1hsla($2, $3, $4, ".concat(alphaValue, ")"));
|
|
6594
|
-
|
|
6595
|
-
// Handle hex colors - convert to rgba
|
|
6596
|
-
modifiedDeclaration = modifiedDeclaration.replace(patterns.hex, (match, propPart, hexColor) => {
|
|
6597
|
-
// Convert hex to rgba
|
|
6598
|
-
const hex = hexColor.replace("#", "");
|
|
6599
|
-
let r, g, b;
|
|
6600
|
-
if (hex.length === 3) {
|
|
6601
|
-
r = parseInt(hex[0] + hex[0], 16);
|
|
6602
|
-
g = parseInt(hex[1] + hex[1], 16);
|
|
6603
|
-
b = parseInt(hex[2] + hex[2], 16);
|
|
6604
|
-
} else {
|
|
6605
|
-
r = parseInt(hex.substring(0, 2), 16);
|
|
6606
|
-
g = parseInt(hex.substring(2, 4), 16);
|
|
6607
|
-
b = parseInt(hex.substring(4, 6), 16);
|
|
6608
|
-
}
|
|
6609
|
-
return "".concat(propPart, "rgba(").concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(alphaValue, ")");
|
|
6610
|
-
});
|
|
6611
|
-
}
|
|
6612
|
-
return modifiedDeclaration;
|
|
6613
|
-
}
|
|
6614
|
-
|
|
6615
7032
|
// Performance monitoring utilities
|
|
6616
7033
|
const performanceMonitor = {
|
|
6617
7034
|
enabled: typeof performance !== "undefined",
|
|
@@ -6688,9 +7105,11 @@ function expandGroupedClass(input) {
|
|
|
6688
7105
|
} while (result !== prev);
|
|
6689
7106
|
return result;
|
|
6690
7107
|
}
|
|
6691
|
-
// CSS Processing utilities
|
|
7108
|
+
// CSS Processing utilities
|
|
6692
7109
|
const parseSelectorCache = new LRUCache(500);
|
|
6693
|
-
|
|
7110
|
+
|
|
7111
|
+
// Parse selector with @css property support (different from parser/selector.js)
|
|
7112
|
+
function parseSelectorWithCssProperty(selector) {
|
|
6694
7113
|
if (parseSelectorCache.has(selector)) {
|
|
6695
7114
|
return parseSelectorCache.get(selector);
|
|
6696
7115
|
}
|
|
@@ -6715,10 +7134,10 @@ function parseSelector(selector) {
|
|
|
6715
7134
|
}
|
|
6716
7135
|
function processClass(cls, selector, styles) {
|
|
6717
7136
|
if (cls.trim() === "") return;
|
|
6718
|
-
const
|
|
6719
|
-
|
|
6720
|
-
rawVariants =
|
|
6721
|
-
className =
|
|
7137
|
+
const _ref = cls.includes(":") ? [cls.split(":").slice(0, -1), cls.split(":").slice(-1)[0]] : [[], cls],
|
|
7138
|
+
_ref2 = _slicedToArray(_ref, 2),
|
|
7139
|
+
rawVariants = _ref2[0],
|
|
7140
|
+
className = _ref2[1];
|
|
6722
7141
|
let isImportant = false;
|
|
6723
7142
|
let pureClassName = className;
|
|
6724
7143
|
if (className.startsWith("!")) {
|
|
@@ -6796,10 +7215,10 @@ function processNestedSelectors(nested, selector, styles, walk) {
|
|
|
6796
7215
|
const nestedVal = nested[nestedSel];
|
|
6797
7216
|
if (nestedSel === "@css" && typeof nestedVal === "object") {
|
|
6798
7217
|
// For @css directive, use raw CSS values without any processing
|
|
6799
|
-
const cssDeclarations = Object.entries(nestedVal).map(
|
|
6800
|
-
let
|
|
6801
|
-
key =
|
|
6802
|
-
value =
|
|
7218
|
+
const cssDeclarations = Object.entries(nestedVal).map(_ref3 => {
|
|
7219
|
+
let _ref4 = _slicedToArray(_ref3, 2),
|
|
7220
|
+
key = _ref4[0],
|
|
7221
|
+
value = _ref4[1];
|
|
6803
7222
|
// Convert camelCase to kebab-case (e.g., borderTopColor -> border-top-color)
|
|
6804
7223
|
const cssKey = key.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
6805
7224
|
// Ensure CSS values are properly formatted and not processed through Tailwind conversion
|
|
@@ -6822,9 +7241,9 @@ function walkStyleTree(selector, val, styles, walk) {
|
|
|
6822
7241
|
logger.warn("Invalid selector in walk function:", selector);
|
|
6823
7242
|
return;
|
|
6824
7243
|
}
|
|
6825
|
-
const
|
|
6826
|
-
baseSelector =
|
|
6827
|
-
cssProperty =
|
|
7244
|
+
const _parseSelectorWithCss = parseSelectorWithCssProperty(selector),
|
|
7245
|
+
baseSelector = _parseSelectorWithCss.baseSelector,
|
|
7246
|
+
cssProperty = _parseSelectorWithCss.cssProperty;
|
|
6828
7247
|
if (cssProperty && typeof val === "object" && Array.isArray(val) && val.length > 0) {
|
|
6829
7248
|
const cssValue = val[0];
|
|
6830
7249
|
if (typeof cssValue === "string") {
|
|
@@ -6863,9 +7282,9 @@ function walkStyleTree(selector, val, styles, walk) {
|
|
|
6863
7282
|
}
|
|
6864
7283
|
walk(selector, [expandGroupedClass(val)]);
|
|
6865
7284
|
} else if (typeof val === "object" && val !== null) {
|
|
6866
|
-
const
|
|
6867
|
-
baseSelector =
|
|
6868
|
-
cssProperty =
|
|
7285
|
+
const _parseSelectorWithCss2 = parseSelectorWithCssProperty(selector),
|
|
7286
|
+
baseSelector = _parseSelectorWithCss2.baseSelector,
|
|
7287
|
+
cssProperty = _parseSelectorWithCss2.cssProperty;
|
|
6869
7288
|
if (cssProperty) {
|
|
6870
7289
|
const cssValue = Object.values(val).join(" ");
|
|
6871
7290
|
styles[baseSelector] = styles[baseSelector] || "";
|
|
@@ -6876,10 +7295,10 @@ function walkStyleTree(selector, val, styles, walk) {
|
|
|
6876
7295
|
// Check if this is a @css object within the current object
|
|
6877
7296
|
if (val["@css"] && typeof val["@css"] === "object") {
|
|
6878
7297
|
// Handle object with @css directive - process the @css part specially
|
|
6879
|
-
const cssDeclarations = Object.entries(val["@css"]).map(
|
|
6880
|
-
let
|
|
6881
|
-
key =
|
|
6882
|
-
value =
|
|
7298
|
+
const cssDeclarations = Object.entries(val["@css"]).map(_ref5 => {
|
|
7299
|
+
let _ref6 = _slicedToArray(_ref5, 2),
|
|
7300
|
+
key = _ref6[0],
|
|
7301
|
+
value = _ref6[1];
|
|
6883
7302
|
// Convert camelCase to kebab-case (e.g., borderTopColor -> border-top-color)
|
|
6884
7303
|
const cssKey = key.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
6885
7304
|
// Keep CSS values intact without any processing
|
|
@@ -7025,9 +7444,9 @@ function generateCssString(styles) {
|
|
|
7025
7444
|
let cssString = "";
|
|
7026
7445
|
|
|
7027
7446
|
// Add base styles
|
|
7028
|
-
for (const
|
|
7029
|
-
const sel =
|
|
7030
|
-
const css =
|
|
7447
|
+
for (const _ref7 of baseStyles) {
|
|
7448
|
+
const sel = _ref7.sel;
|
|
7449
|
+
const css = _ref7.css;
|
|
7031
7450
|
cssString += "".concat(sel, "{").concat(css.trim().replace(/\n/g, ""), "}");
|
|
7032
7451
|
}
|
|
7033
7452
|
|
|
@@ -7037,9 +7456,9 @@ function generateCssString(styles) {
|
|
|
7037
7456
|
return match ? parseInt(match[1], 10) : 99999;
|
|
7038
7457
|
}
|
|
7039
7458
|
mediaStyles.sort((a, b) => mediaPriority(a.sel) - mediaPriority(b.sel));
|
|
7040
|
-
for (const
|
|
7041
|
-
const sel =
|
|
7042
|
-
const content =
|
|
7459
|
+
for (const _ref8 of mediaStyles) {
|
|
7460
|
+
const sel = _ref8.sel;
|
|
7461
|
+
const content = _ref8.content;
|
|
7043
7462
|
cssString += "".concat(sel, "{");
|
|
7044
7463
|
for (const subSel in content) {
|
|
7045
7464
|
cssString += "".concat(subSel, "{").concat(content[subSel].trim().replace(/\n/g, ""), "}");
|
|
@@ -7236,14 +7655,14 @@ function twsxNoCache(obj) {
|
|
|
7236
7655
|
})
|
|
7237
7656
|
});
|
|
7238
7657
|
const configOptions = getConfigOptions(mergedOptions, Object.keys(plugins));
|
|
7239
|
-
const
|
|
7240
|
-
|
|
7241
|
-
keyframes =
|
|
7658
|
+
const _ref9 = configOptions.theme || {},
|
|
7659
|
+
_ref9$keyframes = _ref9.keyframes,
|
|
7660
|
+
keyframes = _ref9$keyframes === void 0 ? {} : _ref9$keyframes;
|
|
7242
7661
|
let customKeyframesCSS = "";
|
|
7243
|
-
for (const
|
|
7244
|
-
var
|
|
7245
|
-
const name =
|
|
7246
|
-
const keyframe =
|
|
7662
|
+
for (const _ref0 of Object.entries(keyframes)) {
|
|
7663
|
+
var _ref1 = _slicedToArray(_ref0, 2);
|
|
7664
|
+
const name = _ref1[0];
|
|
7665
|
+
const keyframe = _ref1[1];
|
|
7247
7666
|
// Skip if already in built-in keyframes or already injected
|
|
7248
7667
|
if (BUILTIN_KEYFRAMES[name] || _injectedKeyframes.has(name)) continue;
|
|
7249
7668
|
|
|
@@ -7254,15 +7673,15 @@ function twsxNoCache(obj) {
|
|
|
7254
7673
|
|
|
7255
7674
|
// Generate minified custom keyframe
|
|
7256
7675
|
customKeyframesCSS += "@keyframes ".concat(name, "{");
|
|
7257
|
-
for (const
|
|
7258
|
-
var
|
|
7259
|
-
const percentage =
|
|
7260
|
-
const styles =
|
|
7676
|
+
for (const _ref10 of Object.entries(keyframe)) {
|
|
7677
|
+
var _ref11 = _slicedToArray(_ref10, 2);
|
|
7678
|
+
const percentage = _ref11[0];
|
|
7679
|
+
const styles = _ref11[1];
|
|
7261
7680
|
customKeyframesCSS += "".concat(percentage, "{");
|
|
7262
|
-
for (const
|
|
7263
|
-
var
|
|
7264
|
-
const prop =
|
|
7265
|
-
const value =
|
|
7681
|
+
for (const _ref12 of Object.entries(styles)) {
|
|
7682
|
+
var _ref13 = _slicedToArray(_ref12, 2);
|
|
7683
|
+
const prop = _ref13[0];
|
|
7684
|
+
const value = _ref13[1];
|
|
7266
7685
|
const cssProp = prop.replace(UPPERCASE_LETTER_REGEX, "-$1").toLowerCase();
|
|
7267
7686
|
customKeyframesCSS += "".concat(cssProp, ":").concat(value, ";");
|
|
7268
7687
|
}
|
|
@@ -7418,109 +7837,14 @@ function twsx(obj) {
|
|
|
7418
7837
|
return result;
|
|
7419
7838
|
}
|
|
7420
7839
|
|
|
7421
|
-
//
|
|
7422
|
-
|
|
7423
|
-
|
|
7424
|
-
|
|
7425
|
-
|
|
7426
|
-
|
|
7427
|
-
|
|
7428
|
-
|
|
7429
|
-
hash = (hash << 5) - hash + chr;
|
|
7430
|
-
hash |= 0; // Convert to 32bit integer
|
|
7431
|
-
}
|
|
7432
|
-
return hash;
|
|
7433
|
-
}
|
|
7434
|
-
|
|
7435
|
-
// Enhanced auto-inject CSS with performance monitoring & SSR support
|
|
7436
|
-
const injectedCssHashSet = new Set();
|
|
7437
|
-
|
|
7438
|
-
// Registry of sourceKey → cssBlock for smart slot-based replacement.
|
|
7439
|
-
// Prevents stale CSS chunks from accumulating across HMR cycles.
|
|
7440
|
-
const _cssBlockRegistry = new Map();
|
|
7441
|
-
|
|
7442
|
-
/**
|
|
7443
|
-
* Rebuild the single twsx style tag from the full CSS block registry.
|
|
7444
|
-
* Called whenever a block is added or updated.
|
|
7445
|
-
*/
|
|
7446
|
-
function rebuildStyleTag$1() {
|
|
7447
|
-
let styleTag = document.getElementById("twsx-auto-style");
|
|
7448
|
-
if (!styleTag) {
|
|
7449
|
-
styleTag = document.createElement("style");
|
|
7450
|
-
styleTag.id = "twsx-auto-style";
|
|
7451
|
-
styleTag.setAttribute("data-twsx", "");
|
|
7452
|
-
document.head.appendChild(styleTag);
|
|
7453
|
-
}
|
|
7454
|
-
styleTag.textContent = [..._cssBlockRegistry.values()].join("\n");
|
|
7455
|
-
}
|
|
7456
|
-
function autoInjectCss(cssString) {
|
|
7457
|
-
let sourceKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
7458
|
-
const marker = performanceMonitor.start("css:inject");
|
|
7459
|
-
try {
|
|
7460
|
-
// SSR mode: collect CSS strings instead of DOM injection. Delegates to
|
|
7461
|
-
// the shared collector in ./utils/ssr.js so both the legacy
|
|
7462
|
-
// startSSR()/stopSSR() pair and the modern createSSRCollector() actually
|
|
7463
|
-
// receive the CSS generated by tw()/twsx().
|
|
7464
|
-
if (isSSRCollecting()) {
|
|
7465
|
-
collectSSRCSS(cssString);
|
|
7466
|
-
performanceMonitor.end(marker);
|
|
7467
|
-
return;
|
|
7468
|
-
}
|
|
7469
|
-
if (IS_BROWSER$1) {
|
|
7470
|
-
if (sourceKey) {
|
|
7471
|
-
// Slot-based update: each unique twsx(obj) call owns its own CSS block.
|
|
7472
|
-
// When styles change (new content, same logical call site via cacheKey)
|
|
7473
|
-
// the old slot is replaced and the style tag is fully rebuilt, so no
|
|
7474
|
-
// stale rules from previous HMR cycles can pile up.
|
|
7475
|
-
const existing = _cssBlockRegistry.get(sourceKey);
|
|
7476
|
-
if (existing === cssString) {
|
|
7477
|
-
// Identical content – nothing to do.
|
|
7478
|
-
performanceMonitor.end(marker);
|
|
7479
|
-
return;
|
|
7480
|
-
}
|
|
7481
|
-
_cssBlockRegistry.set(sourceKey, cssString);
|
|
7482
|
-
rebuildStyleTag$1();
|
|
7483
|
-
if (_cssBlockRegistry.size % 10 === 0) {
|
|
7484
|
-
logger.debug("CSS registry stats: ".concat(_cssBlockRegistry.size, " blocks registered"));
|
|
7485
|
-
}
|
|
7486
|
-
performanceMonitor.end(marker);
|
|
7487
|
-
return;
|
|
7488
|
-
}
|
|
7489
|
-
|
|
7490
|
-
// Fallback path (e.g. direct autoInjectCss calls without a sourceKey):
|
|
7491
|
-
// keep the original hash-based dedup + append behaviour.
|
|
7492
|
-
const cssHash = getCssHash(cssString);
|
|
7493
|
-
if (injectedCssHashSet.has(cssHash)) {
|
|
7494
|
-
performanceMonitor.end(marker);
|
|
7495
|
-
return;
|
|
7496
|
-
}
|
|
7497
|
-
injectedCssHashSet.add(cssHash);
|
|
7498
|
-
evictSet(injectedCssHashSet);
|
|
7499
|
-
let styleTag = document.getElementById("twsx-auto-style");
|
|
7500
|
-
if (!styleTag) {
|
|
7501
|
-
styleTag = document.createElement("style");
|
|
7502
|
-
styleTag.id = "twsx-auto-style";
|
|
7503
|
-
styleTag.setAttribute("data-twsx", "");
|
|
7504
|
-
document.head.appendChild(styleTag);
|
|
7505
|
-
}
|
|
7506
|
-
|
|
7507
|
-
// Append CSS to style tag using textContent for reliability
|
|
7508
|
-
// Note: insertRule + textContent mixing destroys CSSOM rules,
|
|
7509
|
-
// so we use textContent exclusively for consistent behavior
|
|
7510
|
-
// with @keyframes, @media, and other nested CSS blocks.
|
|
7511
|
-
styleTag.textContent += "\n".concat(cssString);
|
|
7512
|
-
|
|
7513
|
-
// Log injection stats periodically
|
|
7514
|
-
if (injectedCssHashSet.size % 10 === 0) {
|
|
7515
|
-
logger.debug("CSS injection stats: ".concat(injectedCssHashSet.size, " unique stylesheets injected"));
|
|
7516
|
-
}
|
|
7517
|
-
}
|
|
7518
|
-
performanceMonitor.end(marker);
|
|
7519
|
-
} catch (error) {
|
|
7520
|
-
performanceMonitor.end(marker);
|
|
7521
|
-
logger.error("Error injecting CSS:", error);
|
|
7522
|
-
}
|
|
7523
|
-
}
|
|
7840
|
+
// ============================================================================
|
|
7841
|
+
// Main API Exports
|
|
7842
|
+
// ============================================================================
|
|
7843
|
+
// twsxClassName - Unified CSS-in-JS API with variants and slots
|
|
7844
|
+
// tw - Atomic CSS class generator with pseudo-class support
|
|
7845
|
+
// REMOVED: Re-export removed to break circular dependency
|
|
7846
|
+
// Import directly from './className/index.js' if needed
|
|
7847
|
+
// export { twsxClassName, tw } from "./className/index.js";
|
|
7524
7848
|
|
|
7525
7849
|
const _excluded = ["name", "prefix", "hash", "hashLength", "inject", "_"],
|
|
7526
7850
|
_excluded2 = ["class", "className"],
|