chaincss 2.2.0 → 2.3.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/dist/compiler/accessibility-engine.d.ts +57 -0
- package/dist/compiler/constraint-solver.d.ts +85 -0
- package/dist/compiler/intent-api.d.ts +73 -0
- package/dist/compiler/layout-intelligence.d.ts +71 -0
- package/dist/compiler/pass-manager.d.ts +157 -0
- package/dist/compiler/pattern-learner.d.ts +112 -0
- package/dist/compiler/responsive-inference.d.ts +63 -0
- package/dist/compiler/semantic-tokens.d.ts +57 -0
- package/dist/compiler/source-optimizer.d.ts +109 -0
- package/dist/compiler/style-ir.d.ts +183 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +3475 -0
- package/package.json +1 -1
- package/src/compiler/accessibility-engine.ts +502 -0
- package/src/compiler/constraint-solver.ts +407 -0
- package/src/compiler/intent-api.ts +505 -0
- package/src/compiler/layout-intelligence.ts +697 -0
- package/src/compiler/pass-manager.ts +657 -0
- package/src/compiler/pattern-learner.ts +398 -0
- package/src/compiler/responsive-inference.ts +415 -0
- package/src/compiler/semantic-tokens.ts +468 -0
- package/src/compiler/source-optimizer.ts +541 -0
- package/src/compiler/style-ir.ts +495 -0
- package/src/index.ts +175 -0
- package/ROADMAP.md +0 -31
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source-Aware Optimization Engine
|
|
3
|
+
*
|
|
4
|
+
* Unifies all analysis modules into an enterprise-grade optimization report.
|
|
5
|
+
* Tracks where every style originates and detects:
|
|
6
|
+
* - Duplicate styles across files
|
|
7
|
+
* - Dead/unreachable rules
|
|
8
|
+
* - Specificity wars
|
|
9
|
+
* - Conflicting animations
|
|
10
|
+
* - Redundant media queries
|
|
11
|
+
* - Unused variants and recipes
|
|
12
|
+
*/
|
|
13
|
+
import type { IRRule, IRPass } from './style-ir.js';
|
|
14
|
+
export interface DuplicateGroup {
|
|
15
|
+
/** The shared signature */
|
|
16
|
+
signature: string;
|
|
17
|
+
/** All occurrences with source locations */
|
|
18
|
+
occurrences: Array<{
|
|
19
|
+
selector: string;
|
|
20
|
+
file?: string;
|
|
21
|
+
line?: number;
|
|
22
|
+
component?: string;
|
|
23
|
+
}>;
|
|
24
|
+
/** How many times it appears */
|
|
25
|
+
count: number;
|
|
26
|
+
/** Suggested extraction */
|
|
27
|
+
suggestion: string;
|
|
28
|
+
/** Estimated savings in bytes */
|
|
29
|
+
savingsBytes: number;
|
|
30
|
+
}
|
|
31
|
+
export interface DeadRule {
|
|
32
|
+
ruleId: string;
|
|
33
|
+
selector: string;
|
|
34
|
+
file?: string;
|
|
35
|
+
line?: number;
|
|
36
|
+
reason: string;
|
|
37
|
+
bytesWasted: number;
|
|
38
|
+
}
|
|
39
|
+
export interface SpecificityConflict {
|
|
40
|
+
higher: {
|
|
41
|
+
selector: string;
|
|
42
|
+
specificity: number;
|
|
43
|
+
file?: string;
|
|
44
|
+
line?: number;
|
|
45
|
+
};
|
|
46
|
+
lower: {
|
|
47
|
+
selector: string;
|
|
48
|
+
specificity: number;
|
|
49
|
+
file?: string;
|
|
50
|
+
line?: number;
|
|
51
|
+
};
|
|
52
|
+
property?: string;
|
|
53
|
+
severity: 'warning' | 'info';
|
|
54
|
+
}
|
|
55
|
+
export interface AnimationConflict {
|
|
56
|
+
name: string;
|
|
57
|
+
locations: Array<{
|
|
58
|
+
file?: string;
|
|
59
|
+
line?: number;
|
|
60
|
+
selector: string;
|
|
61
|
+
}>;
|
|
62
|
+
count: number;
|
|
63
|
+
}
|
|
64
|
+
export interface MediaQueryRedundancy {
|
|
65
|
+
query: string;
|
|
66
|
+
count: number;
|
|
67
|
+
files: string[];
|
|
68
|
+
suggestion: string;
|
|
69
|
+
savingsBytes: number;
|
|
70
|
+
}
|
|
71
|
+
export interface OptimizationReport {
|
|
72
|
+
duplicates: DuplicateGroup[];
|
|
73
|
+
deadRules: DeadRule[];
|
|
74
|
+
specificityConflicts: SpecificityConflict[];
|
|
75
|
+
animationConflicts: AnimationConflict[];
|
|
76
|
+
mediaQueryRedundancies: MediaQueryRedundancy[];
|
|
77
|
+
summary: {
|
|
78
|
+
totalIssues: number;
|
|
79
|
+
duplicatesCount: number;
|
|
80
|
+
deadCount: number;
|
|
81
|
+
specificityCount: number;
|
|
82
|
+
animationCount: number;
|
|
83
|
+
mediaQueryCount: number;
|
|
84
|
+
totalSavingsBytes: number;
|
|
85
|
+
totalSavingsKB: string;
|
|
86
|
+
};
|
|
87
|
+
formattedReport: string;
|
|
88
|
+
}
|
|
89
|
+
declare function findDuplicates(rules: IRRule[]): DuplicateGroup[];
|
|
90
|
+
declare function findDeadRules(rules: IRRule[]): DeadRule[];
|
|
91
|
+
declare function findSpecificityConflicts(rules: IRRule[]): SpecificityConflict[];
|
|
92
|
+
declare function findAnimationConflicts(rules: IRRule[]): AnimationConflict[];
|
|
93
|
+
declare function findMediaQueryRedundancies(rules: IRRule[]): MediaQueryRedundancy[];
|
|
94
|
+
declare function formatReport(report: OptimizationReport): string;
|
|
95
|
+
declare function generateOptimizationReport(rules: IRRule[]): OptimizationReport;
|
|
96
|
+
export declare const sourceOptimizerPass: IRPass;
|
|
97
|
+
export declare function optimizeSource(rules: IRRule[]): OptimizationReport;
|
|
98
|
+
export declare const sourceOptimizer: {
|
|
99
|
+
optimize: typeof optimizeSource;
|
|
100
|
+
findDuplicates: typeof findDuplicates;
|
|
101
|
+
findDeadRules: typeof findDeadRules;
|
|
102
|
+
findSpecificityConflicts: typeof findSpecificityConflicts;
|
|
103
|
+
findAnimationConflicts: typeof findAnimationConflicts;
|
|
104
|
+
findMediaQueryRedundancies: typeof findMediaQueryRedundancies;
|
|
105
|
+
report: typeof generateOptimizationReport;
|
|
106
|
+
format: typeof formatReport;
|
|
107
|
+
pass: IRPass;
|
|
108
|
+
};
|
|
109
|
+
export default sourceOptimizer;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChainCSS Intermediate Representation (IR)
|
|
3
|
+
*
|
|
4
|
+
* The single source of truth that all compiler passes read from and write to.
|
|
5
|
+
* Replaces direct object mutation with a typed, traceable AST.
|
|
6
|
+
*
|
|
7
|
+
* Architecture:
|
|
8
|
+
* StyleDefinition → parseIR() → StyleIR → [passes] → generateCSS()
|
|
9
|
+
*/
|
|
10
|
+
import type { StyleDefinition } from '../core/types.js';
|
|
11
|
+
/** Unique identifier for every IR node */
|
|
12
|
+
export type IRNodeId = string;
|
|
13
|
+
/** Source location for debugging and source maps */
|
|
14
|
+
export interface SourceLocation {
|
|
15
|
+
file?: string;
|
|
16
|
+
line?: number;
|
|
17
|
+
column?: number;
|
|
18
|
+
component?: string;
|
|
19
|
+
}
|
|
20
|
+
/** A single CSS declaration (property: value) */
|
|
21
|
+
export interface IRDeclaration {
|
|
22
|
+
id: IRNodeId;
|
|
23
|
+
property: string;
|
|
24
|
+
value: string | number;
|
|
25
|
+
important?: boolean;
|
|
26
|
+
source?: SourceLocation;
|
|
27
|
+
/** Transform history — who modified this and why */
|
|
28
|
+
history: IRTransformRecord[];
|
|
29
|
+
/** Metadata from passes */
|
|
30
|
+
meta: Record<string, any>;
|
|
31
|
+
}
|
|
32
|
+
/** A CSS rule (selector + declarations + nested rules) */
|
|
33
|
+
export interface IRRule {
|
|
34
|
+
id: IRNodeId;
|
|
35
|
+
selector: string;
|
|
36
|
+
declarations: IRDeclaration[];
|
|
37
|
+
pseudoClasses: IRPseudoClass[];
|
|
38
|
+
atRules: IRAtRule[];
|
|
39
|
+
nestedRules: IRRule[];
|
|
40
|
+
/** Conditional if() expressions */
|
|
41
|
+
conditions: IRCondition[];
|
|
42
|
+
/** Dead code flag — set by optimizer passes */
|
|
43
|
+
isDead: boolean;
|
|
44
|
+
/** Specificity — set by graph pass */
|
|
45
|
+
specificity: number;
|
|
46
|
+
/** Content hash for deduplication */
|
|
47
|
+
hash: string;
|
|
48
|
+
source: SourceLocation;
|
|
49
|
+
history: IRTransformRecord[];
|
|
50
|
+
meta: Record<string, any>;
|
|
51
|
+
}
|
|
52
|
+
/** Pseudo-class block (hover, focus, etc.) */
|
|
53
|
+
export interface IRPseudoClass {
|
|
54
|
+
id: IRNodeId;
|
|
55
|
+
name: string;
|
|
56
|
+
declarations: IRDeclaration[];
|
|
57
|
+
source: SourceLocation;
|
|
58
|
+
history: IRTransformRecord[];
|
|
59
|
+
}
|
|
60
|
+
/** At-rule block (media, keyframes, supports, etc.) */
|
|
61
|
+
export interface IRAtRule {
|
|
62
|
+
id: IRNodeId;
|
|
63
|
+
type: 'media' | 'keyframes' | 'font-face' | 'supports' | 'container' | 'layer';
|
|
64
|
+
query?: string;
|
|
65
|
+
name?: string;
|
|
66
|
+
declarations: IRDeclaration[];
|
|
67
|
+
nestedRules: IRRule[];
|
|
68
|
+
source: SourceLocation;
|
|
69
|
+
history: IRTransformRecord[];
|
|
70
|
+
}
|
|
71
|
+
/** CSS if() conditional */
|
|
72
|
+
export interface IRCondition {
|
|
73
|
+
id: IRNodeId;
|
|
74
|
+
property: string;
|
|
75
|
+
variable: string;
|
|
76
|
+
conditions: Record<string, string | number>;
|
|
77
|
+
defaultValue: string | number;
|
|
78
|
+
source: SourceLocation;
|
|
79
|
+
}
|
|
80
|
+
/** Transform record — who touched this node and why */
|
|
81
|
+
export interface IRTransformRecord {
|
|
82
|
+
pass: string;
|
|
83
|
+
action: string;
|
|
84
|
+
timestamp: number;
|
|
85
|
+
previous?: any;
|
|
86
|
+
reason?: string;
|
|
87
|
+
}
|
|
88
|
+
/** The full IR tree */
|
|
89
|
+
export interface StyleIR {
|
|
90
|
+
id: string;
|
|
91
|
+
rules: IRRule[];
|
|
92
|
+
diagnostics: IRDiagnostic[];
|
|
93
|
+
meta: {
|
|
94
|
+
version: string;
|
|
95
|
+
createdAt: number;
|
|
96
|
+
sourceFiles: string[];
|
|
97
|
+
passCount: number;
|
|
98
|
+
passes: string[];
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/** Diagnostic attached to an IR node */
|
|
102
|
+
export interface IRDiagnostic {
|
|
103
|
+
id: IRNodeId;
|
|
104
|
+
nodeId: IRNodeId;
|
|
105
|
+
severity: 'error' | 'warning' | 'info' | 'hint';
|
|
106
|
+
message: string;
|
|
107
|
+
suggestion?: string;
|
|
108
|
+
pass: string;
|
|
109
|
+
}
|
|
110
|
+
export declare function resetIdCounter(): void;
|
|
111
|
+
export declare function createDeclaration(property: string, value: string | number, source?: SourceLocation, meta?: Record<string, any>): IRDeclaration;
|
|
112
|
+
export declare function createRule(selector: string, source?: SourceLocation): IRRule;
|
|
113
|
+
export declare function createIR(sourceFiles?: string[]): StyleIR;
|
|
114
|
+
/**
|
|
115
|
+
* Parse a StyleDefinition (or Record<string, any>) into the IR.
|
|
116
|
+
* This is the bridge — existing code produces StyleDefinition,
|
|
117
|
+
* this converts it to typed IR for all downstream passes.
|
|
118
|
+
*/
|
|
119
|
+
export declare function parseIR(styles: Record<string, StyleDefinition> | Record<string, any>, sourceFile?: string): StyleIR;
|
|
120
|
+
/**
|
|
121
|
+
* Generate a CSS string from the IR.
|
|
122
|
+
* This replaces the ad-hoc CSS generation scattered across modules.
|
|
123
|
+
*/
|
|
124
|
+
export declare function generateCSS(ir: StyleIR, options?: {
|
|
125
|
+
minify?: boolean;
|
|
126
|
+
}): string;
|
|
127
|
+
/** Count all nodes in the IR */
|
|
128
|
+
export declare function countNodes(ir: StyleIR): {
|
|
129
|
+
rules: number;
|
|
130
|
+
declarations: number;
|
|
131
|
+
pseudoClasses: number;
|
|
132
|
+
atRules: number;
|
|
133
|
+
conditions: number;
|
|
134
|
+
};
|
|
135
|
+
/** Find a rule by selector */
|
|
136
|
+
export declare function findRule(ir: StyleIR, selector: string): IRRule | undefined;
|
|
137
|
+
/** Clone an IR (deep copy) */
|
|
138
|
+
export declare function cloneIR(ir: StyleIR): StyleIR;
|
|
139
|
+
/** Debug: print IR summary */
|
|
140
|
+
export declare function debugIR(ir: StyleIR): string;
|
|
141
|
+
export type IRPass = (ir: StyleIR) => StyleIR;
|
|
142
|
+
/**
|
|
143
|
+
* Apply a transform pass to the IR.
|
|
144
|
+
* Records the pass in metadata for debugging.
|
|
145
|
+
*/
|
|
146
|
+
export declare function applyPass(ir: StyleIR, pass: IRPass, passName: string): StyleIR;
|
|
147
|
+
/**
|
|
148
|
+
* Apply multiple passes in sequence.
|
|
149
|
+
*/
|
|
150
|
+
export declare function applyPasses(ir: StyleIR, passes: Array<{
|
|
151
|
+
name: string;
|
|
152
|
+
pass: IRPass;
|
|
153
|
+
}>): StyleIR;
|
|
154
|
+
/**
|
|
155
|
+
* Full pipeline: StyleDefinition → IR → passes → CSS.
|
|
156
|
+
* Drop-in replacement for existing compile() calls.
|
|
157
|
+
*/
|
|
158
|
+
export declare function compileViaIR(styles: Record<string, StyleDefinition>, passes?: Array<{
|
|
159
|
+
name: string;
|
|
160
|
+
pass: IRPass;
|
|
161
|
+
}>, options?: {
|
|
162
|
+
minify?: boolean;
|
|
163
|
+
sourceFile?: string;
|
|
164
|
+
}): {
|
|
165
|
+
css: string;
|
|
166
|
+
ir: StyleIR;
|
|
167
|
+
};
|
|
168
|
+
export declare const styleIR: {
|
|
169
|
+
createIR: typeof createIR;
|
|
170
|
+
parseIR: typeof parseIR;
|
|
171
|
+
generateCSS: typeof generateCSS;
|
|
172
|
+
createRule: typeof createRule;
|
|
173
|
+
createDeclaration: typeof createDeclaration;
|
|
174
|
+
countNodes: typeof countNodes;
|
|
175
|
+
findRule: typeof findRule;
|
|
176
|
+
cloneIR: typeof cloneIR;
|
|
177
|
+
debugIR: typeof debugIR;
|
|
178
|
+
applyPass: typeof applyPass;
|
|
179
|
+
applyPasses: typeof applyPasses;
|
|
180
|
+
compileViaIR: typeof compileViaIR;
|
|
181
|
+
resetIdCounter: typeof resetIdCounter;
|
|
182
|
+
};
|
|
183
|
+
export default styleIR;
|
package/dist/index.d.ts
CHANGED
|
@@ -44,6 +44,25 @@ export { orchestrator, contrastRatio, checkContrast, auditContrast, createContex
|
|
|
44
44
|
export type { ContrastResult, ContrastReport, ContextualToken, TokenContext } from './compiler/design-orchestrator.js';
|
|
45
45
|
export { scrollTimeline, compileScrollAnimation, compileScrollAnimations, createScrollAnimation, getScrollPresets, SCROLL_PRESETS, } from './compiler/scroll-timeline.js';
|
|
46
46
|
export type { ScrollTimelineConfig, ScrollAnimation, ScrollTimelineResult, KeyframeStep } from './compiler/scroll-timeline.js';
|
|
47
|
+
export { styleIR, createIR, parseIR, generateCSS, createRule, createDeclaration, applyPass, applyPasses, compileViaIR, countNodes, debugIR, resetIdCounter, } from './compiler/style-ir.js';
|
|
48
|
+
export type { StyleIR, IRRule, IRDeclaration, IRPseudoClass, IRAtRule, IRCondition, IRTransformRecord, IRDiagnostic, IRNodeId, SourceLocation, IRPass, } from './compiler/style-ir.js';
|
|
49
|
+
export { PassManager, runDefaultPipeline, DEFAULT_PIPELINE, intentRecoveryPass, unitResolutionPass, validationPass, specificitySortPass, deadEliminationPass, atomicExtractionPass, mediaQueryPackingPass, cssIfTranspilePass, cssCompressionPass, diagnosticsExportPass, } from './compiler/pass-manager.js';
|
|
50
|
+
export type { PassName, PassPriority, PassDefinition, PassResult, PipelineResult } from './compiler/pass-manager.js';
|
|
51
|
+
export { constraintSolver, resolveConstraint, resolveStickyUntil, resolveContainerQuery, parseConstraint, constraintSolverPass, } from './compiler/constraint-solver.js';
|
|
52
|
+
export type { Constraint, ConstraintOperator, ConstraintTarget, ResolvedConstraint } from './compiler/constraint-solver.js';
|
|
53
|
+
export { layoutIntelligence, recognizeLayout, suggestMacro, getLayoutPatterns, layoutIntelligencePass, } from './compiler/layout-intelligence.js';
|
|
54
|
+
export type { LayoutPattern, PatternMatch, PatternReport } from './compiler/layout-intelligence.js';
|
|
55
|
+
export { responsiveInference, analyzeResponsive, generateResponsiveReport, autoFixIssue, autoFixAll, responsiveInferencePass, } from './compiler/responsive-inference.js';
|
|
56
|
+
export type { ResponsiveIssue, ResponsiveReport } from './compiler/responsive-inference.js';
|
|
57
|
+
export { patternLearner, learnPatterns, getExtractionCandidates, patternLearningPass, } from './compiler/pattern-learner.js';
|
|
58
|
+
export type { StyleFingerprint, PatternCluster, LearningReport } from './compiler/pattern-learner.js';
|
|
59
|
+
export { sourceOptimizer, optimizeSource, sourceOptimizerPass, } from './compiler/source-optimizer.js';
|
|
60
|
+
export type { OptimizationReport, DuplicateGroup, DeadRule, SpecificityConflict, AnimationConflict, MediaQueryRedundancy } from './compiler/source-optimizer.js';
|
|
61
|
+
export { semanticTokens, resolveSemantic, getSemanticIntents, getSemanticDescription, semanticTokensPass, } from './compiler/semantic-tokens.js';
|
|
62
|
+
export type { SurfaceIntent, TextIntent, ElevationIntent, StateIntent, SpacingIntent, SemanticMapping, ThemeContext } from './compiler/semantic-tokens.js';
|
|
63
|
+
export { accessibilityEngine, auditAccessibility, checkRule, accessibilityPass, } from './compiler/accessibility-engine.js';
|
|
64
|
+
export type { AccessibilityIssue, AccessibilityReport } from './compiler/accessibility-engine.js';
|
|
65
|
+
export { intentAPI, resolveIntent, getAvailableIntents, getIntentsByCategory, getIntentDescription, intentAPIPass, } from './compiler/intent-api.js';
|
|
47
66
|
import { chain } from './compiler/Chain.js';
|
|
48
67
|
export default chain;
|
|
49
68
|
export type { Properties as CSSProperties } from 'csstype';
|