chaincss 2.1.37 → 2.1.39

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/src/core/types.ts CHANGED
@@ -256,4 +256,210 @@ export function isCompileResult(value: any): value is CompileResult {
256
256
  typeof value.css === 'string' &&
257
257
  typeof value.classMap === 'object' &&
258
258
  typeof value.stats === 'object';
259
+ }
260
+
261
+ // ============================================================================
262
+ // 🆕 Math Engine Types (v3.0)
263
+ // ============================================================================
264
+
265
+ export type CSSUnit =
266
+ | 'px' | 'rem' | 'em' | '%'
267
+ | 'vw' | 'vh' | 'vmin' | 'vmax'
268
+ | 'ch' | 'ex' | 'cm' | 'mm' | 'in' | 'pt' | 'pc'
269
+ | 'deg' | 'rad' | 'turn' | 'grad'
270
+ | 's' | 'ms'
271
+ | 'dpi' | 'dpcm' | 'dppx';
272
+
273
+ export interface CSSMathValue {
274
+ value: number;
275
+ unit: CSSUnit;
276
+ }
277
+
278
+ export interface MathContext {
279
+ rootFontSize?: number; // px, default 16
280
+ viewportWidth?: number; // px, default 1920
281
+ viewportHeight?: number; // px, default 1080
282
+ parentFontSize?: number; // px, default 16
283
+ dpi?: number; // default 96
284
+ elementWidth?: number; // px
285
+ elementHeight?: number; // px
286
+ }
287
+
288
+ export interface MathResult {
289
+ value: number;
290
+ unit: CSSUnit | 'calc' | 'mixed';
291
+ expression: string;
292
+ resolved: CSSMathValue | null;
293
+ explanations: string[];
294
+ toString(): string;
295
+ toCalc(): string;
296
+ }
297
+
298
+ export interface FluidTypeConfig {
299
+ minSize: number;
300
+ maxSize: number;
301
+ minWidth?: number; // default 320
302
+ maxWidth?: number; // default 1280
303
+ unit?: 'px' | 'rem';
304
+ rootFontSize?: number; // for rem conversion
305
+ }
306
+
307
+ // ============================================================================
308
+ // 🆕 Self-Healing / Intent Engine Types (v3.0)
309
+ // ============================================================================
310
+
311
+ export interface IntentRule {
312
+ input: string | RegExp;
313
+ output: string | ((match: RegExpMatchArray) => string);
314
+ defaults?: Record<string, string | number>;
315
+ confidence: number;
316
+ description: string;
317
+ }
318
+
319
+ export interface CorrectionResult {
320
+ original: string;
321
+ property: string;
322
+ corrected: string;
323
+ defaults: Record<string, string | number>;
324
+ confidence: number;
325
+ intent: string;
326
+ explanation: string;
327
+ }
328
+
329
+ export interface IntentContext {
330
+ property?: string;
331
+ value?: string;
332
+ selector?: string;
333
+ parentStyles?: Record<string, any>;
334
+ mediaContext?: string;
335
+ themeContext?: string;
336
+ }
337
+
338
+ export type HealMode = 'strict' | 'dev' | 'smart';
339
+
340
+ export interface HealResult {
341
+ fixed: Record<string, any>;
342
+ corrections: CorrectionResult[];
343
+ warnings: string[];
344
+ mode: HealMode;
345
+ }
346
+
347
+ // ============================================================================
348
+ // 🆕 Style Graph Types (v3.0)
349
+ // ============================================================================
350
+
351
+ export interface StyleGraphNode {
352
+ id: string;
353
+ selector: string;
354
+ properties: Record<string, string | number>;
355
+ specificity: number;
356
+ dependencies: string[];
357
+ dependents: string[];
358
+ mediaQuery?: string;
359
+ isDead: boolean;
360
+ hash: string;
361
+ sourceComponent?: string;
362
+ }
363
+
364
+ export interface StyleGraphEdge {
365
+ from: string;
366
+ to: string;
367
+ type: 'extends' | 'overrides' | 'references';
368
+ }
369
+
370
+ export interface StyleGraph {
371
+ nodes: Map<string, StyleGraphNode>;
372
+ edges: StyleGraphEdge[];
373
+ rootNodes: string[];
374
+ leafNodes: string[];
375
+ }
376
+
377
+ export interface GraphCompileOptions {
378
+ eliminateDead?: boolean;
379
+ knownSelectors?: string[];
380
+ mergeIdentical?: boolean;
381
+ mergeThreshold?: number; // min properties to consider merging
382
+ sortOutput?: 'specificity' | 'source-order' | 'topological';
383
+ verbose?: boolean;
384
+ }
385
+
386
+ export interface GraphCompileResult extends CompileResult {
387
+ graph: StyleGraph;
388
+ eliminatedDead: number;
389
+ mergedRules: number;
390
+ optimizationTime: number;
391
+ preOptimizationSize: number;
392
+ postOptimizationSize: number;
393
+ }
394
+
395
+ // ============================================================================
396
+ // 🆕 Analyzer / IDE Types (v3.0)
397
+ // ============================================================================
398
+
399
+ export type DiagnosticSeverity = 'error' | 'warning' | 'info' | 'hint';
400
+
401
+ export interface StyleDiagnostic {
402
+ property: string;
403
+ value?: string;
404
+ selector?: string;
405
+ severity: DiagnosticSeverity;
406
+ message: string;
407
+ suggestion?: string;
408
+ code?: string;
409
+ source?: string;
410
+ range?: {
411
+ startLine: number;
412
+ startColumn: number;
413
+ endLine: number;
414
+ endColumn: number;
415
+ };
416
+ }
417
+
418
+ export interface StyleAnalysis {
419
+ diagnostics: StyleDiagnostic[];
420
+ conflicts: StyleDiagnostic[];
421
+ breakpoints: BreakpointConfig[];
422
+ unusedSelectors: string[];
423
+ deadStyles: string[];
424
+ duplicationWarnings: StyleDiagnostic[];
425
+ optimizationSuggestions: StyleDiagnostic[];
426
+ stats: {
427
+ totalProperties: number;
428
+ totalSelectors: number;
429
+ shorthandOpportunities: number;
430
+ animationSuggestions: number;
431
+ responsiveIssues: number;
432
+ };
433
+ }
434
+
435
+ export interface BreakpointInference {
436
+ selector: string;
437
+ property: string;
438
+ currentValue: string;
439
+ suggestedBreakpoint: string;
440
+ suggestedValue: string;
441
+ reason: string;
442
+ }
443
+
444
+ // ============================================================================
445
+ // 🆕 Type Guards for new types
446
+ // ============================================================================
447
+
448
+ export function isMathResult(value: any): value is MathResult {
449
+ return value && typeof value === 'object' &&
450
+ typeof value.expression === 'string' &&
451
+ typeof value.toString === 'function';
452
+ }
453
+
454
+ export function isCorrectionResult(value: any): value is CorrectionResult {
455
+ return value && typeof value === 'object' &&
456
+ typeof value.original === 'string' &&
457
+ typeof value.corrected === 'string' &&
458
+ typeof value.confidence === 'number';
459
+ }
460
+
461
+ export function isGraphCompileResult(value: any): value is GraphCompileResult {
462
+ return isCompileResult(value) &&
463
+ typeof (value as any).graph === 'object' &&
464
+ typeof (value as any).eliminatedDead === 'number';
259
465
  }
package/src/index.ts CHANGED
@@ -207,4 +207,72 @@ export type ResponsiveValue<T> = T | {
207
207
 
208
208
  export type StyleWithTokens<T = any> = T | ((tokens: DesignTokens) => T);
209
209
 
210
- import { DesignTokens } from './compiler/tokens.js';
210
+ import { DesignTokens } from './compiler/tokens.js';
211
+
212
+ // ============================================================================
213
+ // 🆕 Math Engine (v3.0)
214
+ // ============================================================================
215
+ export {
216
+ math,
217
+ add,
218
+ subtract,
219
+ multiply,
220
+ divide,
221
+ fluidType,
222
+ convert,
223
+ toPx,
224
+ scale
225
+ } from './compiler/math-engine.js';
226
+ export type {
227
+ CSSUnit,
228
+ CSSMathValue,
229
+ MathContext,
230
+ MathResult,
231
+ FluidTypeConfig
232
+ } from './compiler/math-engine.js';
233
+
234
+ // ============================================================================
235
+ // 🆕 Intent Engine — Self-Healing CSS (v3.0)
236
+ // ============================================================================
237
+ export {
238
+ intent,
239
+ correct,
240
+ heal,
241
+ validate as validateValue,
242
+ getIntent
243
+ } from './compiler/intent-engine.js';
244
+ export type {
245
+ CorrectionResult,
246
+ HealMode,
247
+ HealResult,
248
+ IntentContext
249
+ } from './compiler/intent-engine.js';
250
+
251
+ // ============================================================================
252
+ // 🆕 Style Graph Compiler (v3.0)
253
+ // ============================================================================
254
+ export {
255
+ StyleGraphCompiler,
256
+ compileGraph
257
+ } from './compiler/style-graph.js';
258
+ export type {
259
+ StyleGraph,
260
+ StyleGraphNode,
261
+ StyleGraphEdge,
262
+ GraphCompileOptions,
263
+ GraphCompileResult
264
+ } from './compiler/style-graph.js';
265
+
266
+ // ============================================================================
267
+ // 🆕 Static Analyzer — IDE Intelligence Layer (v3.0)
268
+ // ============================================================================
269
+ export {
270
+ StyleAnalyzer,
271
+ analyze as analyzeStyle
272
+ } from './compiler/analyzer.js';
273
+ export type {
274
+ StyleDiagnostic,
275
+ StyleAnalysis,
276
+ BreakpointInference,
277
+ DiagnosticSeverity
278
+ } from './compiler/analyzer.js';
@@ -276,7 +276,15 @@ export default function chaincssPlugin(options: ChainCSSPluginOptions = {}): Plu
276
276
 
277
277
  if (id === resolvedCssId) {
278
278
  const css = updateCSS();
279
- return css || '/* ChainCSS: No styles */';
279
+ // Return JS that injects the CSS into the DOM
280
+ if (css && css.trim()) {
281
+ return `const style = document.createElement('style');
282
+ style.setAttribute('data-chaincss', 'build');
283
+ style.textContent = ${JSON.stringify(css)};
284
+ document.head.appendChild(style);
285
+ export default {};`;
286
+ }
287
+ return 'export default {};';
280
288
  }
281
289
 
282
290
  return null;
package/demo/index.html DELETED
@@ -1,16 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>ChainCSS Demo | Zero-Runtime CSS-in-JS</title>
7
- <style>
8
- *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
9
- body { font-family: 'Inter', system-ui, -apple-system, sans-serif; -webkit-font-smoothing: antialiased; }
10
- </style>
11
- </head>
12
- <body>
13
- <div id="app"></div>
14
- <script type="module" src="/src/main.tsx"></script>
15
- </body>
16
- </html>
package/demo/package.json DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "name": "chaincss-demo",
3
- "private": true,
4
- "type": "module",
5
- "scripts": {
6
- "dev": "vite",
7
- "build": "vite build"
8
- },
9
- "dependencies": {
10
- "autoprefixer": "^10.5.0",
11
- "browserslist": "^4.28.2",
12
- "caniuse-lite": "^1.0.30001791",
13
- "react": "^18.2.0",
14
- "react-dom": "^18.2.0"
15
- },
16
- "devDependencies": {
17
- "@vitejs/plugin-react": "^4.0.0",
18
- "vite": "^5.0.0"
19
- }
20
- }
package/demo/src/App.tsx DELETED
@@ -1,117 +0,0 @@
1
- import React from 'react';
2
- import * as S from './styles.chain';
3
-
4
- const features = [
5
- { icon: '⚡', title: 'Zero Runtime', desc: 'Static styles compile to plain CSS. No JavaScript shipped for styling.' },
6
- { icon: '🎯', title: 'Auto Detection', desc: 'smartChain() detects static vs dynamic automatically.' },
7
- { icon: '🧩', title: '57 Macros', desc: 'flex(), center(), glass(), pill() — complex CSS as single method calls.' },
8
- { icon: '🎨', title: 'Design Tokens', desc: 'Themeable with full token resolution system.' },
9
- { icon: '🔄', title: 'Variant System', desc: 'Type-safe component variants with compound conditions.' },
10
- { icon: '📱', title: 'Responsive', desc: '20 breakpoints. Mobile-first to feature queries.' },
11
- ];
12
-
13
- const plans = [
14
- { name: 'Starter', price: 'Free', features: ['5 components', 'Basic macros', 'Community support'], featured: false },
15
- { name: 'Pro', price: '$29/mo', features: ['Unlimited components', 'All 57 macros', 'Priority support', 'Atomic CSS', 'Design tokens'], featured: true },
16
- { name: 'Enterprise', price: '$99/mo', features: ['Everything in Pro', 'Theme contracts', 'SSR support', 'Custom plugins', 'Dedicated support'], featured: false },
17
- ];
18
-
19
- export function App() {
20
- return (
21
- <div style={{ background: '#0f172a', minHeight: '100vh' }}>
22
- {/* NAV */}
23
- <nav className={S.nav.selectors?.[0]}>
24
- <div className={S.navInner.selectors?.[0]}>
25
- <span className={S.navLogo.selectors?.[0]}>ChainCSS</span>
26
- <div className={S.navLinks.selectors?.[0]}>
27
- {['Features', 'Pricing', 'Docs', 'GitHub'].map(item => (
28
- <a key={item} href="#" className={S.navLink.selectors?.[0]}>{item}</a>
29
- ))}
30
- </div>
31
- </div>
32
- </nav>
33
-
34
- {/* HERO */}
35
- <section className={S.hero.selectors?.[0]}>
36
- <h1 className={S.heroTitle.selectors?.[0]}>
37
- Write Styles Like JavaScript.<br />Ship Zero Runtime.
38
- </h1>
39
- <p className={S.heroSubtitle.selectors?.[0]}>
40
- ChainCSS auto-detects static vs dynamic styles. CSS where possible, JS where needed.
41
- </p>
42
- <div style={{ display: 'flex', gap: 16 }}>
43
- <button className={S.buttonPrimary.selectors?.[0]}>Get Started →</button>
44
- <button className={S.buttonSecondary.selectors?.[0]}>View on GitHub</button>
45
- </div>
46
- </section>
47
-
48
- {/* FEATURES */}
49
- <section className={S.section.selectors?.[0]}>
50
- <div className={S.sectionHeader.selectors?.[0]}>
51
- <h2 className={S.sectionTitle.selectors?.[0]}>Everything You Need</h2>
52
- <p className={S.sectionDesc.selectors?.[0]}>550+ features. One JavaScript API. Zero runtime CSS.</p>
53
- </div>
54
- <div className={S.featureGrid.selectors?.[0]}>
55
- {features.map(f => (
56
- <div key={f.title} className={S.featureCard.selectors?.[0]}>
57
- <div className={S.featureIcon.selectors?.[0]}>{f.icon}</div>
58
- <h3 className={S.featureTitle.selectors?.[0]}>{f.title}</h3>
59
- <p className={S.featureDesc.selectors?.[0]}>{f.desc}</p>
60
- </div>
61
- ))}
62
- </div>
63
- </section>
64
-
65
- {/* PRICING */}
66
- <section className={S.section.selectors?.[0]}>
67
- <div className={S.sectionHeader.selectors?.[0]}>
68
- <h2 className={S.sectionTitle.selectors?.[0]}>Simple Pricing</h2>
69
- <p className={S.sectionDesc.selectors?.[0]}>Start free, scale as you grow.</p>
70
- </div>
71
- <div className={S.pricingGrid.selectors?.[0]}>
72
- {plans.map(p => (
73
- <div key={p.name} className={(p.featured ? S.pricingCardFeatured : S.pricingCard).selectors?.[0]}>
74
- {p.featured && <span className={S.pricingBadge.selectors?.[0]}>POPULAR</span>}
75
- <h3 className={S.pricingPlanName.selectors?.[0]}>{p.name}</h3>
76
- <div className={S.pricingPrice.selectors?.[0]}>{p.price}</div>
77
- <div style={{ flex: 1, marginBottom: 24 }}>
78
- {p.features.map(f => (
79
- <div key={f} className={S.pricingFeature.selectors?.[0]}>✓ {f}</div>
80
- ))}
81
- </div>
82
- <button className={(p.featured ? S.buttonPrimary : S.buttonSecondary).selectors?.[0]}>
83
- Get Started
84
- </button>
85
- </div>
86
- ))}
87
- </div>
88
- </section>
89
-
90
- {/* FOOTER */}
91
- <footer className={S.footer.selectors?.[0]}>
92
- <div className={S.footerGrid.selectors?.[0]}>
93
- <div>
94
- <h4 className={S.footerHeading.selectors?.[0]}>ChainCSS</h4>
95
- <a href="#" className={S.footerLink.selectors?.[0]}>About</a>
96
- <a href="#" className={S.footerLink.selectors?.[0]}>Blog</a>
97
- </div>
98
- <div>
99
- <h4 className={S.footerHeading.selectors?.[0]}>Product</h4>
100
- <a href="#" className={S.footerLink.selectors?.[0]}>Features</a>
101
- <a href="#" className={S.footerLink.selectors?.[0]}>Pricing</a>
102
- </div>
103
- <div>
104
- <h4 className={S.footerHeading.selectors?.[0]}>Resources</h4>
105
- <a href="#" className={S.footerLink.selectors?.[0]}>Docs</a>
106
- <a href="#" className={S.footerLink.selectors?.[0]}>Examples</a>
107
- </div>
108
- <div>
109
- <h4 className={S.footerHeading.selectors?.[0]}>Legal</h4>
110
- <a href="#" className={S.footerLink.selectors?.[0]}>Privacy</a>
111
- <a href="#" className={S.footerLink.selectors?.[0]}>Terms</a>
112
- </div>
113
- </div>
114
- </footer>
115
- </div>
116
- );
117
- }
@@ -1,9 +0,0 @@
1
- // Lightweight barrel for demo - excludes compiler/prefixer
2
- export { chain, enableDebug, setTokenContext, getTokenContext } from '../../src/compiler/Chain.js';
3
- export { recipe } from '../../src/compiler/btt.js';
4
- export { createTokens, DesignTokens } from '../../src/compiler/tokens.js';
5
- export { smartChain, buildChain, runtimeChain } from '../../src/core/smart-chain.js';
6
- export { createThemeContract, createTheme, validateTheme, Theme } from '../../src/compiler/theme-contract.js';
7
- export { helpers } from '../../src/compiler/helpers.js';
8
- export { animationPresets, createAnimation, getAnimationPreset } from '../../src/compiler/animations.js';
9
- export { shorthandMap, macros } from '../../src/compiler/shorthands.js';
package/demo/src/main.tsx DELETED
@@ -1,8 +0,0 @@
1
- import React from 'react';
2
- import { createRoot } from 'react-dom/client';
3
- import { App } from './App';
4
-
5
- const root = document.getElementById('app');
6
- if (root) {
7
- createRoot(root).render(<App />);
8
- }