chaincss 2.1.13 → 2.1.15
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/cli/index.js +1 -54
- package/dist/index.js +12 -54
- package/dist/plugins/vite.js +1 -54
- package/dist/runtime/index.js +11 -0
- package/package.json +1 -1
- package/src/core/compiler.ts +1 -72
- package/src/runtime/index.ts +18 -0
package/dist/cli/index.js
CHANGED
|
@@ -2834,61 +2834,8 @@ var init_compiler = __esm({
|
|
|
2834
2834
|
if (!this.atomicOptimizer || id.includes("\0")) return;
|
|
2835
2835
|
try {
|
|
2836
2836
|
let processedCount = 0;
|
|
2837
|
-
let searchFrom = 0;
|
|
2838
|
-
while (true) {
|
|
2839
|
-
const startIdx = source.indexOf("useChainStyles({", searchFrom);
|
|
2840
|
-
if (startIdx === -1) break;
|
|
2841
|
-
const braceStart = source.indexOf("{", startIdx);
|
|
2842
|
-
if (braceStart === -1) break;
|
|
2843
|
-
let braceCount = 0;
|
|
2844
|
-
let endIdx = -1;
|
|
2845
|
-
for (let i = braceStart; i < source.length; i++) {
|
|
2846
|
-
if (source[i] === "{") braceCount++;
|
|
2847
|
-
if (source[i] === "}") braceCount--;
|
|
2848
|
-
if (braceCount === 0) {
|
|
2849
|
-
endIdx = i;
|
|
2850
|
-
break;
|
|
2851
|
-
}
|
|
2852
|
-
}
|
|
2853
|
-
if (endIdx === -1) break;
|
|
2854
|
-
const stylesBlock = source.substring(braceStart + 1, endIdx);
|
|
2855
|
-
try {
|
|
2856
|
-
const componentRegex = /(\w+):\s*\{/g;
|
|
2857
|
-
let componentMatch;
|
|
2858
|
-
while ((componentMatch = componentRegex.exec(stylesBlock)) !== null) {
|
|
2859
|
-
const componentKey = componentMatch[1];
|
|
2860
|
-
const componentStart = componentMatch.index + componentMatch[0].length;
|
|
2861
|
-
let compBraceCount = 0;
|
|
2862
|
-
let compEndIdx = -1;
|
|
2863
|
-
for (let i = componentStart - 1; i < stylesBlock.length; i++) {
|
|
2864
|
-
if (stylesBlock[i] === "{") compBraceCount++;
|
|
2865
|
-
if (stylesBlock[i] === "}") compBraceCount--;
|
|
2866
|
-
if (compBraceCount === 0) {
|
|
2867
|
-
compEndIdx = i;
|
|
2868
|
-
break;
|
|
2869
|
-
}
|
|
2870
|
-
}
|
|
2871
|
-
if (compEndIdx === -1) continue;
|
|
2872
|
-
const componentStyles = stylesBlock.substring(componentStart, compEndIdx);
|
|
2873
|
-
const rawObj = this.safeParseStyleObject(`{${componentStyles}}`);
|
|
2874
|
-
if (Object.keys(rawObj).length === 0) continue;
|
|
2875
|
-
const expandedObj = {};
|
|
2876
|
-
for (const [k, v] of Object.entries(rawObj)) {
|
|
2877
|
-
const realKey = shorthandMap[k] || k;
|
|
2878
|
-
expandedObj[realKey] = v;
|
|
2879
|
-
}
|
|
2880
|
-
await this.processStyleObject(expandedObj, componentKey);
|
|
2881
|
-
processedCount++;
|
|
2882
|
-
}
|
|
2883
|
-
} catch (parseError) {
|
|
2884
|
-
if (this.config.verbose) {
|
|
2885
|
-
console.warn(chalk3.yellow(` \u26A0\uFE0F Failed to parse styles in ${id}: ${parseError}`));
|
|
2886
|
-
}
|
|
2887
|
-
}
|
|
2888
|
-
searchFrom = endIdx + 1;
|
|
2889
|
-
}
|
|
2890
2837
|
if (this.config.verbose && processedCount > 0) {
|
|
2891
|
-
console.log(
|
|
2838
|
+
console.log(` \u2514\u2500 Processed ${processedCount} chain() styles from ${id.split("/").pop()}`);
|
|
2892
2839
|
}
|
|
2893
2840
|
} catch (error) {
|
|
2894
2841
|
console.error(chalk3.red(` \u274C Error compiling source ${id}: ${error}`));
|
package/dist/index.js
CHANGED
|
@@ -3353,8 +3353,18 @@ var compileRuntime = (s, moduleId) => styleInjector.injectMultiple(s, moduleId);
|
|
|
3353
3353
|
// src/runtime/index.ts
|
|
3354
3354
|
function injectChainStyles(styles) {
|
|
3355
3355
|
let css = "";
|
|
3356
|
+
let staticCount = 0, dynamicCount = 0, hybridCount = 0;
|
|
3356
3357
|
for (const [key, obj] of Object.entries(styles)) {
|
|
3357
3358
|
if (!obj || !obj.selectors) continue;
|
|
3359
|
+
let stat = 0, dyn = 0;
|
|
3360
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
3361
|
+
if (["selectors", "hover", "atRules", "nestedRules", "_name", "_classes", "__buildClasses", "__runtimeClasses", "__isHybrid"].includes(k)) continue;
|
|
3362
|
+
if (typeof v === "function") dyn++;
|
|
3363
|
+
else stat++;
|
|
3364
|
+
}
|
|
3365
|
+
if (stat > 0 && dyn > 0) hybridCount++;
|
|
3366
|
+
else if (dyn > 0) dynamicCount++;
|
|
3367
|
+
else staticCount++;
|
|
3358
3368
|
const sel = "." + obj.selectors[0];
|
|
3359
3369
|
css += sel + "{";
|
|
3360
3370
|
for (const [k, v] of Object.entries(obj)) {
|
|
@@ -3379,6 +3389,7 @@ function injectChainStyles(styles) {
|
|
|
3379
3389
|
el.setAttribute("data-chaincss", "runtime");
|
|
3380
3390
|
el.textContent = css;
|
|
3381
3391
|
document.head.appendChild(el);
|
|
3392
|
+
console.log("\u26D3\uFE0F ChainCSS Split: \u{1F4E6} Static=" + staticCount + " \u26A1 Dynamic=" + dynamicCount + " \u{1F500} Hybrid=" + hybridCount + " | CSS: " + css.length + " bytes");
|
|
3382
3393
|
return el;
|
|
3383
3394
|
}
|
|
3384
3395
|
|
|
@@ -6352,61 +6363,8 @@ var ChainCSSCompiler = class {
|
|
|
6352
6363
|
if (!this.atomicOptimizer || id.includes("\0")) return;
|
|
6353
6364
|
try {
|
|
6354
6365
|
let processedCount = 0;
|
|
6355
|
-
let searchFrom = 0;
|
|
6356
|
-
while (true) {
|
|
6357
|
-
const startIdx = source.indexOf("useChainStyles({", searchFrom);
|
|
6358
|
-
if (startIdx === -1) break;
|
|
6359
|
-
const braceStart = source.indexOf("{", startIdx);
|
|
6360
|
-
if (braceStart === -1) break;
|
|
6361
|
-
let braceCount = 0;
|
|
6362
|
-
let endIdx = -1;
|
|
6363
|
-
for (let i = braceStart; i < source.length; i++) {
|
|
6364
|
-
if (source[i] === "{") braceCount++;
|
|
6365
|
-
if (source[i] === "}") braceCount--;
|
|
6366
|
-
if (braceCount === 0) {
|
|
6367
|
-
endIdx = i;
|
|
6368
|
-
break;
|
|
6369
|
-
}
|
|
6370
|
-
}
|
|
6371
|
-
if (endIdx === -1) break;
|
|
6372
|
-
const stylesBlock = source.substring(braceStart + 1, endIdx);
|
|
6373
|
-
try {
|
|
6374
|
-
const componentRegex = /(\w+):\s*\{/g;
|
|
6375
|
-
let componentMatch;
|
|
6376
|
-
while ((componentMatch = componentRegex.exec(stylesBlock)) !== null) {
|
|
6377
|
-
const componentKey = componentMatch[1];
|
|
6378
|
-
const componentStart = componentMatch.index + componentMatch[0].length;
|
|
6379
|
-
let compBraceCount = 0;
|
|
6380
|
-
let compEndIdx = -1;
|
|
6381
|
-
for (let i = componentStart - 1; i < stylesBlock.length; i++) {
|
|
6382
|
-
if (stylesBlock[i] === "{") compBraceCount++;
|
|
6383
|
-
if (stylesBlock[i] === "}") compBraceCount--;
|
|
6384
|
-
if (compBraceCount === 0) {
|
|
6385
|
-
compEndIdx = i;
|
|
6386
|
-
break;
|
|
6387
|
-
}
|
|
6388
|
-
}
|
|
6389
|
-
if (compEndIdx === -1) continue;
|
|
6390
|
-
const componentStyles = stylesBlock.substring(componentStart, compEndIdx);
|
|
6391
|
-
const rawObj = this.safeParseStyleObject(`{${componentStyles}}`);
|
|
6392
|
-
if (Object.keys(rawObj).length === 0) continue;
|
|
6393
|
-
const expandedObj = {};
|
|
6394
|
-
for (const [k, v] of Object.entries(rawObj)) {
|
|
6395
|
-
const realKey = shorthandMap[k] || k;
|
|
6396
|
-
expandedObj[realKey] = v;
|
|
6397
|
-
}
|
|
6398
|
-
await this.processStyleObject(expandedObj, componentKey);
|
|
6399
|
-
processedCount++;
|
|
6400
|
-
}
|
|
6401
|
-
} catch (parseError) {
|
|
6402
|
-
if (this.config.verbose) {
|
|
6403
|
-
console.warn(chalk3.yellow(` \u26A0\uFE0F Failed to parse styles in ${id}: ${parseError}`));
|
|
6404
|
-
}
|
|
6405
|
-
}
|
|
6406
|
-
searchFrom = endIdx + 1;
|
|
6407
|
-
}
|
|
6408
6366
|
if (this.config.verbose && processedCount > 0) {
|
|
6409
|
-
console.log(
|
|
6367
|
+
console.log(` \u2514\u2500 Processed ${processedCount} chain() styles from ${id.split("/").pop()}`);
|
|
6410
6368
|
}
|
|
6411
6369
|
} catch (error) {
|
|
6412
6370
|
console.error(chalk3.red(` \u274C Error compiling source ${id}: ${error}`));
|
package/dist/plugins/vite.js
CHANGED
|
@@ -2739,61 +2739,8 @@ var ChainCSSCompiler = class {
|
|
|
2739
2739
|
if (!this.atomicOptimizer || id.includes("\0")) return;
|
|
2740
2740
|
try {
|
|
2741
2741
|
let processedCount = 0;
|
|
2742
|
-
let searchFrom = 0;
|
|
2743
|
-
while (true) {
|
|
2744
|
-
const startIdx = source.indexOf("useChainStyles({", searchFrom);
|
|
2745
|
-
if (startIdx === -1) break;
|
|
2746
|
-
const braceStart = source.indexOf("{", startIdx);
|
|
2747
|
-
if (braceStart === -1) break;
|
|
2748
|
-
let braceCount = 0;
|
|
2749
|
-
let endIdx = -1;
|
|
2750
|
-
for (let i = braceStart; i < source.length; i++) {
|
|
2751
|
-
if (source[i] === "{") braceCount++;
|
|
2752
|
-
if (source[i] === "}") braceCount--;
|
|
2753
|
-
if (braceCount === 0) {
|
|
2754
|
-
endIdx = i;
|
|
2755
|
-
break;
|
|
2756
|
-
}
|
|
2757
|
-
}
|
|
2758
|
-
if (endIdx === -1) break;
|
|
2759
|
-
const stylesBlock = source.substring(braceStart + 1, endIdx);
|
|
2760
|
-
try {
|
|
2761
|
-
const componentRegex = /(\w+):\s*\{/g;
|
|
2762
|
-
let componentMatch;
|
|
2763
|
-
while ((componentMatch = componentRegex.exec(stylesBlock)) !== null) {
|
|
2764
|
-
const componentKey = componentMatch[1];
|
|
2765
|
-
const componentStart = componentMatch.index + componentMatch[0].length;
|
|
2766
|
-
let compBraceCount = 0;
|
|
2767
|
-
let compEndIdx = -1;
|
|
2768
|
-
for (let i = componentStart - 1; i < stylesBlock.length; i++) {
|
|
2769
|
-
if (stylesBlock[i] === "{") compBraceCount++;
|
|
2770
|
-
if (stylesBlock[i] === "}") compBraceCount--;
|
|
2771
|
-
if (compBraceCount === 0) {
|
|
2772
|
-
compEndIdx = i;
|
|
2773
|
-
break;
|
|
2774
|
-
}
|
|
2775
|
-
}
|
|
2776
|
-
if (compEndIdx === -1) continue;
|
|
2777
|
-
const componentStyles = stylesBlock.substring(componentStart, compEndIdx);
|
|
2778
|
-
const rawObj = this.safeParseStyleObject(`{${componentStyles}}`);
|
|
2779
|
-
if (Object.keys(rawObj).length === 0) continue;
|
|
2780
|
-
const expandedObj = {};
|
|
2781
|
-
for (const [k, v] of Object.entries(rawObj)) {
|
|
2782
|
-
const realKey = shorthandMap[k] || k;
|
|
2783
|
-
expandedObj[realKey] = v;
|
|
2784
|
-
}
|
|
2785
|
-
await this.processStyleObject(expandedObj, componentKey);
|
|
2786
|
-
processedCount++;
|
|
2787
|
-
}
|
|
2788
|
-
} catch (parseError) {
|
|
2789
|
-
if (this.config.verbose) {
|
|
2790
|
-
console.warn(chalk2.yellow(` \u26A0\uFE0F Failed to parse styles in ${id}: ${parseError}`));
|
|
2791
|
-
}
|
|
2792
|
-
}
|
|
2793
|
-
searchFrom = endIdx + 1;
|
|
2794
|
-
}
|
|
2795
2742
|
if (this.config.verbose && processedCount > 0) {
|
|
2796
|
-
console.log(
|
|
2743
|
+
console.log(` \u2514\u2500 Processed ${processedCount} chain() styles from ${id.split("/").pop()}`);
|
|
2797
2744
|
}
|
|
2798
2745
|
} catch (error) {
|
|
2799
2746
|
console.error(chalk2.red(` \u274C Error compiling source ${id}: ${error}`));
|
package/dist/runtime/index.js
CHANGED
|
@@ -3909,8 +3909,18 @@ var injectStyleContextSvelte = (...args) => getSvelteExports().injectStyleContex
|
|
|
3909
3909
|
var chainStyles2 = (...args) => getSvelteExports().chainStyles?.(...args);
|
|
3910
3910
|
function injectChainStyles(styles3) {
|
|
3911
3911
|
let css = "";
|
|
3912
|
+
let staticCount = 0, dynamicCount = 0, hybridCount = 0;
|
|
3912
3913
|
for (const [key, obj] of Object.entries(styles3)) {
|
|
3913
3914
|
if (!obj || !obj.selectors) continue;
|
|
3915
|
+
let stat = 0, dyn = 0;
|
|
3916
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
3917
|
+
if (["selectors", "hover", "atRules", "nestedRules", "_name", "_classes", "__buildClasses", "__runtimeClasses", "__isHybrid"].includes(k)) continue;
|
|
3918
|
+
if (typeof v === "function") dyn++;
|
|
3919
|
+
else stat++;
|
|
3920
|
+
}
|
|
3921
|
+
if (stat > 0 && dyn > 0) hybridCount++;
|
|
3922
|
+
else if (dyn > 0) dynamicCount++;
|
|
3923
|
+
else staticCount++;
|
|
3914
3924
|
const sel = "." + obj.selectors[0];
|
|
3915
3925
|
css += sel + "{";
|
|
3916
3926
|
for (const [k, v] of Object.entries(obj)) {
|
|
@@ -3935,6 +3945,7 @@ function injectChainStyles(styles3) {
|
|
|
3935
3945
|
el.setAttribute("data-chaincss", "runtime");
|
|
3936
3946
|
el.textContent = css;
|
|
3937
3947
|
document.head.appendChild(el);
|
|
3948
|
+
console.log("\u26D3\uFE0F ChainCSS Split: \u{1F4E6} Static=" + staticCount + " \u26A1 Dynamic=" + dynamicCount + " \u{1F500} Hybrid=" + hybridCount + " | CSS: " + css.length + " bytes");
|
|
3938
3949
|
return el;
|
|
3939
3950
|
}
|
|
3940
3951
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chaincss",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.15",
|
|
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/core/compiler.ts
CHANGED
|
@@ -196,80 +196,9 @@ export class ChainCSSCompiler {
|
|
|
196
196
|
|
|
197
197
|
try {
|
|
198
198
|
let processedCount = 0;
|
|
199
|
-
let searchFrom = 0;
|
|
200
|
-
|
|
201
|
-
while (true) {
|
|
202
|
-
const startIdx = source.indexOf('useChainStyles({', searchFrom);
|
|
203
|
-
if (startIdx === -1) break;
|
|
204
|
-
|
|
205
|
-
// Find the matching closing brace using brace counting
|
|
206
|
-
const braceStart = source.indexOf('{', startIdx);
|
|
207
|
-
if (braceStart === -1) break;
|
|
208
|
-
|
|
209
|
-
let braceCount = 0;
|
|
210
|
-
let endIdx = -1;
|
|
211
|
-
for (let i = braceStart; i < source.length; i++) {
|
|
212
|
-
if (source[i] === '{') braceCount++;
|
|
213
|
-
if (source[i] === '}') braceCount--;
|
|
214
|
-
if (braceCount === 0) {
|
|
215
|
-
endIdx = i;
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
if (endIdx === -1) break;
|
|
221
|
-
|
|
222
|
-
const stylesBlock = source.substring(braceStart + 1, endIdx);
|
|
223
|
-
|
|
224
|
-
try {
|
|
225
|
-
// Extract component definitions from the block
|
|
226
|
-
const componentRegex = /(\w+):\s*\{/g;
|
|
227
|
-
let componentMatch;
|
|
228
|
-
|
|
229
|
-
while ((componentMatch = componentRegex.exec(stylesBlock)) !== null) {
|
|
230
|
-
const componentKey = componentMatch[1];
|
|
231
|
-
const componentStart = componentMatch.index + componentMatch[0].length;
|
|
232
|
-
|
|
233
|
-
// Find matching closing brace for this component
|
|
234
|
-
let compBraceCount = 0;
|
|
235
|
-
let compEndIdx = -1;
|
|
236
|
-
for (let i = componentStart - 1; i < stylesBlock.length; i++) {
|
|
237
|
-
if (stylesBlock[i] === '{') compBraceCount++;
|
|
238
|
-
if (stylesBlock[i] === '}') compBraceCount--;
|
|
239
|
-
if (compBraceCount === 0) {
|
|
240
|
-
compEndIdx = i;
|
|
241
|
-
break;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
if (compEndIdx === -1) continue;
|
|
246
|
-
|
|
247
|
-
const componentStyles = stylesBlock.substring(componentStart, compEndIdx);
|
|
248
|
-
const rawObj = this.safeParseStyleObject(`{${componentStyles}}`);
|
|
249
|
-
|
|
250
|
-
if (Object.keys(rawObj).length === 0) continue;
|
|
251
|
-
|
|
252
|
-
// Expand shorthands
|
|
253
|
-
const expandedObj: Record<string, any> = {};
|
|
254
|
-
for (const [k, v] of Object.entries(rawObj)) {
|
|
255
|
-
const realKey = shorthandMap[k] || k;
|
|
256
|
-
expandedObj[realKey] = v;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
await this.processStyleObject(expandedObj, componentKey);
|
|
260
|
-
processedCount++;
|
|
261
|
-
}
|
|
262
|
-
} catch (parseError) {
|
|
263
|
-
if (this.config.verbose) {
|
|
264
|
-
console.warn(chalk.yellow(` ⚠️ Failed to parse styles in ${id}: ${parseError}`));
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
searchFrom = endIdx + 1;
|
|
269
|
-
}
|
|
270
199
|
|
|
271
200
|
if (this.config.verbose && processedCount > 0) {
|
|
272
|
-
console.log(
|
|
201
|
+
console.log(` └─ Processed ${processedCount} chain() styles from ${id.split('/').pop()}`);
|
|
273
202
|
}
|
|
274
203
|
} catch (error) {
|
|
275
204
|
console.error(chalk.red(` ❌ Error compiling source ${id}: ${error}`));
|
package/src/runtime/index.ts
CHANGED
|
@@ -92,8 +92,22 @@ export type {
|
|
|
92
92
|
// Auto-inject styles into DOM
|
|
93
93
|
export function injectChainStyles(styles: Record<string, any>) {
|
|
94
94
|
let css = '';
|
|
95
|
+
let staticCount = 0, dynamicCount = 0, hybridCount = 0;
|
|
96
|
+
|
|
95
97
|
for (const [key, obj] of Object.entries(styles)) {
|
|
96
98
|
if (!obj || !obj.selectors) continue;
|
|
99
|
+
|
|
100
|
+
// Count static vs dynamic
|
|
101
|
+
let stat = 0, dyn = 0;
|
|
102
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
103
|
+
if (['selectors','hover','atRules','nestedRules','_name','_classes','__buildClasses','__runtimeClasses','__isHybrid'].includes(k)) continue;
|
|
104
|
+
if (typeof v === 'function') dyn++;
|
|
105
|
+
else stat++;
|
|
106
|
+
}
|
|
107
|
+
if (stat > 0 && dyn > 0) hybridCount++;
|
|
108
|
+
else if (dyn > 0) dynamicCount++;
|
|
109
|
+
else staticCount++;
|
|
110
|
+
|
|
97
111
|
const sel = '.' + obj.selectors[0];
|
|
98
112
|
css += sel + '{';
|
|
99
113
|
for (const [k, v] of Object.entries(obj)) {
|
|
@@ -118,5 +132,9 @@ export function injectChainStyles(styles: Record<string, any>) {
|
|
|
118
132
|
el.setAttribute('data-chaincss', 'runtime');
|
|
119
133
|
el.textContent = css;
|
|
120
134
|
document.head.appendChild(el);
|
|
135
|
+
|
|
136
|
+
// Show split stats in console
|
|
137
|
+
console.log('⛓️ ChainCSS Split: 📦 Static=' + staticCount + ' ⚡ Dynamic=' + dynamicCount + ' 🔀 Hybrid=' + hybridCount + ' | CSS: ' + css.length + ' bytes');
|
|
138
|
+
|
|
121
139
|
return el;
|
|
122
140
|
}
|