chaincss 2.1.11 → 2.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +34 -3
- package/dist/plugins/vite.js +13 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/plugins/vite.ts +16 -0
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* @packageDocumentation
|
|
4
4
|
*/
|
|
5
5
|
export { smartChain, smartChain as chainV3, buildChain, runtimeChain } from './core/smart-chain.js';
|
|
6
|
+
export { injectChainStyles } from './runtime/index.js';
|
|
6
7
|
export { autoDetector, AutoDetector, type ValueType, type Mode } from './core/auto-detector.js';
|
|
7
8
|
export { useSmartStyles, createSmartComponent, withSmartStyles } from './runtime/auto-hooks.js';
|
|
8
9
|
export { ChainCSSCompiler, compileChainCSS } from './core/compiler.js';
|
package/dist/index.js
CHANGED
|
@@ -3065,9 +3065,6 @@ function smartChain(useTokens = true) {
|
|
|
3065
3065
|
var buildChain = (useTokens) => chain(useTokens);
|
|
3066
3066
|
var runtimeChain = (useTokens) => new RuntimeChain(useTokens || true).proxy;
|
|
3067
3067
|
|
|
3068
|
-
// src/runtime/auto-hooks.tsx
|
|
3069
|
-
import React, { useEffect, useRef, useState } from "react";
|
|
3070
|
-
|
|
3071
3068
|
// src/core/common-utils.ts
|
|
3072
3069
|
function kebabCase(str) {
|
|
3073
3070
|
return str.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
@@ -3353,7 +3350,40 @@ ${rules}}
|
|
|
3353
3350
|
var styleInjector = new StyleInjector();
|
|
3354
3351
|
var compileRuntime = (s, moduleId) => styleInjector.injectMultiple(s, moduleId);
|
|
3355
3352
|
|
|
3353
|
+
// src/runtime/index.ts
|
|
3354
|
+
function injectChainStyles(styles) {
|
|
3355
|
+
let css = "";
|
|
3356
|
+
for (const [key, obj] of Object.entries(styles)) {
|
|
3357
|
+
if (!obj || !obj.selectors) continue;
|
|
3358
|
+
const sel = "." + obj.selectors[0];
|
|
3359
|
+
css += sel + "{";
|
|
3360
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
3361
|
+
if (["selectors", "hover", "atRules", "nestedRules", "_name", "_classes"].includes(k)) continue;
|
|
3362
|
+
css += k.replace(/([A-Z])/g, "-$1").toLowerCase() + ":" + v + ";";
|
|
3363
|
+
}
|
|
3364
|
+
css += "}";
|
|
3365
|
+
if (obj.hover) {
|
|
3366
|
+
css += sel + ":hover{";
|
|
3367
|
+
for (const [k, v] of Object.entries(obj.hover)) css += k.replace(/([A-Z])/g, "-$1").toLowerCase() + ":" + v + ";";
|
|
3368
|
+
css += "}";
|
|
3369
|
+
}
|
|
3370
|
+
if (obj.nestedRules) {
|
|
3371
|
+
for (const rule of obj.nestedRules) {
|
|
3372
|
+
css += rule.selector.replace("&", sel) + "{";
|
|
3373
|
+
for (const [k, v] of Object.entries(rule.styles || {})) css += k.replace(/([A-Z])/g, "-$1").toLowerCase() + ":" + v + ";";
|
|
3374
|
+
css += "}";
|
|
3375
|
+
}
|
|
3376
|
+
}
|
|
3377
|
+
}
|
|
3378
|
+
const el = document.createElement("style");
|
|
3379
|
+
el.setAttribute("data-chaincss", "runtime");
|
|
3380
|
+
el.textContent = css;
|
|
3381
|
+
document.head.appendChild(el);
|
|
3382
|
+
return el;
|
|
3383
|
+
}
|
|
3384
|
+
|
|
3356
3385
|
// src/runtime/auto-hooks.tsx
|
|
3386
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
3357
3387
|
function useSmartStyles(styleBuilder, deps = [], options = {}) {
|
|
3358
3388
|
const moduleId = useRef(options.moduleId || `smart-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`);
|
|
3359
3389
|
const [classMap, setClassMap] = useState({});
|
|
@@ -7001,6 +7031,7 @@ export {
|
|
|
7001
7031
|
handleShorthand,
|
|
7002
7032
|
hasAnimationPreset,
|
|
7003
7033
|
helpers,
|
|
7034
|
+
injectChainStyles,
|
|
7004
7035
|
isShorthand,
|
|
7005
7036
|
macros,
|
|
7006
7037
|
recipe,
|
package/dist/plugins/vite.js
CHANGED
|
@@ -3471,6 +3471,11 @@ const setManifest = (manifest) => {
|
|
|
3471
3471
|
log(`Processing: ${fileName}`);
|
|
3472
3472
|
processedFiles.add(id);
|
|
3473
3473
|
await compiler.compileSource(source, id);
|
|
3474
|
+
const css = compiler.getCombinedCSS();
|
|
3475
|
+
if (css && css.trim()) {
|
|
3476
|
+
const ruleCount = (css.match(/\{/g) || []).length;
|
|
3477
|
+
console.log(` \u2514\u2500 Extracted ${ruleCount} CSS rules from ${fileName}`);
|
|
3478
|
+
}
|
|
3474
3479
|
updateCSS();
|
|
3475
3480
|
updateManifest();
|
|
3476
3481
|
if (server && options.hmr !== false) {
|
|
@@ -3526,6 +3531,14 @@ ${source}`,
|
|
|
3526
3531
|
},
|
|
3527
3532
|
buildEnd() {
|
|
3528
3533
|
const finalCSS = updateCSS();
|
|
3534
|
+
const stats = compiler.getStats();
|
|
3535
|
+
console.log("");
|
|
3536
|
+
console.log("[ChainCSS] \u2705 Build complete");
|
|
3537
|
+
console.log(` \u{1F4E6} Static CSS: ${finalCSS.length} bytes`);
|
|
3538
|
+
console.log(` \u26A1 Runtime JS: minimal (dynamic properties only)`);
|
|
3539
|
+
console.log(` \u{1F9E9} Total styles: ${stats.totalStyles || 0} processed`);
|
|
3540
|
+
console.log(` \u{1F4BE} Atomic savings: ${stats.savings || "0%"}`);
|
|
3541
|
+
console.log("");
|
|
3529
3542
|
log(`Build complete - Final CSS: ${finalCSS.length} bytes`);
|
|
3530
3543
|
if (options.cssOutput) {
|
|
3531
3544
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chaincss",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.13",
|
|
4
4
|
"description": "ChainCSS v3.0 - The first CSS-in-JS library with true auto-detection mixed mode. Zero runtime by default, dynamic when you need it.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// 🆕 NEW: Smart Chain API (Auto-detection mixed mode)
|
|
10
10
|
// ============================================================================
|
|
11
11
|
export { smartChain, smartChain as chainV3, buildChain, runtimeChain } from './core/smart-chain.js';
|
|
12
|
+
export { injectChainStyles } from './runtime/index.js';
|
|
12
13
|
export { autoDetector, AutoDetector, type ValueType, type Mode } from './core/auto-detector.js';
|
|
13
14
|
|
|
14
15
|
// ============================================================================
|
package/src/plugins/vite.ts
CHANGED
|
@@ -295,6 +295,13 @@ const setManifest = (manifest) => {
|
|
|
295
295
|
// Compile the source
|
|
296
296
|
await compiler.compileSource(source, id);
|
|
297
297
|
|
|
298
|
+
// Show what was found
|
|
299
|
+
const css = compiler.getCombinedCSS();
|
|
300
|
+
if (css && css.trim()) {
|
|
301
|
+
const ruleCount = (css.match(/\{/g) || []).length;
|
|
302
|
+
console.log(` └─ Extracted ${ruleCount} CSS rules from ${fileName}`);
|
|
303
|
+
}
|
|
304
|
+
|
|
298
305
|
// Update stored data
|
|
299
306
|
updateCSS();
|
|
300
307
|
updateManifest();
|
|
@@ -372,6 +379,15 @@ const setManifest = (manifest) => {
|
|
|
372
379
|
|
|
373
380
|
buildEnd() {
|
|
374
381
|
const finalCSS = updateCSS();
|
|
382
|
+
const stats = compiler.getStats();
|
|
383
|
+
|
|
384
|
+
console.log('');
|
|
385
|
+
console.log('[ChainCSS] ✅ Build complete');
|
|
386
|
+
console.log(` 📦 Static CSS: ${finalCSS.length} bytes`);
|
|
387
|
+
console.log(` ⚡ Runtime JS: minimal (dynamic properties only)`);
|
|
388
|
+
console.log(` 🧩 Total styles: ${stats.totalStyles || 0} processed`);
|
|
389
|
+
console.log(` 💾 Atomic savings: ${stats.savings || '0%'}`);
|
|
390
|
+
console.log('');
|
|
375
391
|
log(`Build complete - Final CSS: ${finalCSS.length} bytes`);
|
|
376
392
|
|
|
377
393
|
// Write CSS to file if output specified
|