chaincss 2.2.0 → 2.3.1
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 +240 -372
- 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,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accessibility Intelligence Engine
|
|
3
|
+
*
|
|
4
|
+
* Build-time WCAG 2.2 compliance checking. Auto-fixes where possible.
|
|
5
|
+
* Runs only in build-time and hybrid-static modes. Zero runtime cost.
|
|
6
|
+
*
|
|
7
|
+
* Detectors:
|
|
8
|
+
* - Contrast ratio (extends design-orchestrator)
|
|
9
|
+
* - Minimum font size (12px)
|
|
10
|
+
* - Touch target size (44×44px)
|
|
11
|
+
* - Missing focus indicators
|
|
12
|
+
* - prefers-reduced-motion
|
|
13
|
+
* - Hover-only interactions
|
|
14
|
+
*/
|
|
15
|
+
import type { IRRule, IRPass } from './style-ir.js';
|
|
16
|
+
export interface AccessibilityIssue {
|
|
17
|
+
ruleId: string;
|
|
18
|
+
selector: string;
|
|
19
|
+
category: 'contrast' | 'font-size' | 'touch-target' | 'focus' | 'motion' | 'hover-only' | 'color-only';
|
|
20
|
+
severity: 'error' | 'warning';
|
|
21
|
+
wcagCriterion: string;
|
|
22
|
+
message: string;
|
|
23
|
+
suggestion: string;
|
|
24
|
+
autoFixable: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface AccessibilityReport {
|
|
27
|
+
issues: AccessibilityIssue[];
|
|
28
|
+
errorCount: number;
|
|
29
|
+
warningCount: number;
|
|
30
|
+
passedCount: number;
|
|
31
|
+
summary: string;
|
|
32
|
+
}
|
|
33
|
+
export declare const accessibilityPass: IRPass;
|
|
34
|
+
export declare function auditAccessibility(rules: IRRule[]): AccessibilityReport;
|
|
35
|
+
export declare function checkRule(rule: IRRule): AccessibilityIssue[];
|
|
36
|
+
export declare const accessibilityEngine: {
|
|
37
|
+
audit: typeof auditAccessibility;
|
|
38
|
+
checkRule: typeof checkRule;
|
|
39
|
+
pass: IRPass;
|
|
40
|
+
wcag: {
|
|
41
|
+
MIN_CONTRAST_AA: number;
|
|
42
|
+
MIN_CONTRAST_AA_LARGE: number;
|
|
43
|
+
MIN_CONTRAST_AAA: number;
|
|
44
|
+
MIN_FONT_SIZE: number;
|
|
45
|
+
MIN_TOUCH_TARGET: number;
|
|
46
|
+
CRITERIA: {
|
|
47
|
+
contrast: string;
|
|
48
|
+
fontSize: string;
|
|
49
|
+
touchTarget: string;
|
|
50
|
+
focus: string;
|
|
51
|
+
motion: string;
|
|
52
|
+
hoverOnly: string;
|
|
53
|
+
colorOnly: string;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export default accessibilityEngine;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constraint-Based Styling Engine
|
|
3
|
+
*
|
|
4
|
+
* Declare relationships, not values. The solver resolves them to CSS.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* .constrain('width', '< parent')
|
|
8
|
+
* .constrain('height', '= width * 0.5')
|
|
9
|
+
* .constrain('sidebar', 'sticky until footer')
|
|
10
|
+
* .constrain('columns', '>= 3 when > 768px')
|
|
11
|
+
*/
|
|
12
|
+
import type { IRPass } from './style-ir.js';
|
|
13
|
+
export type ConstraintOperator = '<' | '>' | '<=' | '>=' | '=' | '!=' | '≈';
|
|
14
|
+
export type ConstraintTarget = 'parent' | 'viewport' | 'sibling' | 'self' | string;
|
|
15
|
+
export interface Constraint {
|
|
16
|
+
property: string;
|
|
17
|
+
operator: ConstraintOperator;
|
|
18
|
+
expression: string;
|
|
19
|
+
target?: ConstraintTarget;
|
|
20
|
+
condition?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ResolvedConstraint {
|
|
23
|
+
constraint: Constraint;
|
|
24
|
+
cssProperty: string;
|
|
25
|
+
cssValue: string;
|
|
26
|
+
method: 'direct' | 'calc' | 'aspect-ratio' | 'container-query' | 'sticky' | 'clamp' | 'custom-property' | 'color-mix';
|
|
27
|
+
explanation: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Parse a constraint expression into structured form.
|
|
31
|
+
*/
|
|
32
|
+
declare function parseExpression(expr: string): {
|
|
33
|
+
left: string;
|
|
34
|
+
operator: string;
|
|
35
|
+
right: string;
|
|
36
|
+
isFunction: boolean;
|
|
37
|
+
functionName?: string;
|
|
38
|
+
functionArgs?: string[];
|
|
39
|
+
};
|
|
40
|
+
declare function resolveReference(ref: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Resolve a single constraint into a CSS property+value.
|
|
43
|
+
*/
|
|
44
|
+
export declare function resolveConstraint(constraint: Constraint, context?: Record<string, string>): ResolvedConstraint;
|
|
45
|
+
/**
|
|
46
|
+
* Resolve sticky-until constraint.
|
|
47
|
+
* "sticky until footer" → position: sticky + scroll-driven animation
|
|
48
|
+
*/
|
|
49
|
+
export declare function resolveStickyUntil(selector: string, untilSelector: string): ResolvedConstraint;
|
|
50
|
+
/**
|
|
51
|
+
* Resolve ">= N when > Xpx" constraints to container queries.
|
|
52
|
+
*/
|
|
53
|
+
export declare function resolveContainerQuery(property: string, operator: string, value: string, condition: string): {
|
|
54
|
+
atRule: {
|
|
55
|
+
type: string;
|
|
56
|
+
query: string;
|
|
57
|
+
declarations: Array<{
|
|
58
|
+
property: string;
|
|
59
|
+
value: string;
|
|
60
|
+
}>;
|
|
61
|
+
};
|
|
62
|
+
explanation: string;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* IR Pass: resolve all constraints in the IR to concrete CSS.
|
|
66
|
+
*/
|
|
67
|
+
export declare const constraintSolverPass: IRPass;
|
|
68
|
+
/**
|
|
69
|
+
* Parse a chain-style constraint call into the Constraint format.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* parseConstraint('width', '< parent')
|
|
73
|
+
* // => { property: 'width', operator: '<', expression: 'parent' }
|
|
74
|
+
*/
|
|
75
|
+
export declare function parseConstraint(property: string, expression: string): Constraint;
|
|
76
|
+
export declare const constraintSolver: {
|
|
77
|
+
resolve: typeof resolveConstraint;
|
|
78
|
+
resolveStickyUntil: typeof resolveStickyUntil;
|
|
79
|
+
resolveContainerQuery: typeof resolveContainerQuery;
|
|
80
|
+
parseConstraint: typeof parseConstraint;
|
|
81
|
+
parseExpression: typeof parseExpression;
|
|
82
|
+
resolveReference: typeof resolveReference;
|
|
83
|
+
pass: IRPass;
|
|
84
|
+
};
|
|
85
|
+
export default constraintSolver;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Intent-Based API
|
|
3
|
+
*
|
|
4
|
+
* The highest-level API — developers declare WHAT they want,
|
|
5
|
+
* the compiler resolves HOW using all available modules.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* chain.intent('card') // → full card component
|
|
9
|
+
* chain.intent('center-content') // → flex/grid centering
|
|
10
|
+
* chain.intent('button-primary') // → accessible blue button
|
|
11
|
+
*/
|
|
12
|
+
import type { IRPass } from './style-ir.js';
|
|
13
|
+
interface IntentDefinition {
|
|
14
|
+
/** Human-readable name */
|
|
15
|
+
name: string;
|
|
16
|
+
/** Category for organization */
|
|
17
|
+
category: 'layout' | 'component' | 'semantic' | 'interaction';
|
|
18
|
+
/** Description */
|
|
19
|
+
description: string;
|
|
20
|
+
/** Semantic tokens to apply */
|
|
21
|
+
semantics?: Array<{
|
|
22
|
+
category: string;
|
|
23
|
+
intent: string;
|
|
24
|
+
}>;
|
|
25
|
+
/** Direct properties (for simple intents) */
|
|
26
|
+
properties?: Record<string, string | number>;
|
|
27
|
+
/** Pseudo-classes */
|
|
28
|
+
states?: Record<string, Record<string, string | number>>;
|
|
29
|
+
/** Responsive overrides */
|
|
30
|
+
responsive?: Record<string, Record<string, string | number>>;
|
|
31
|
+
/** Accessibility requirements */
|
|
32
|
+
a11y?: string[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Resolve an intent into all its constituent parts.
|
|
36
|
+
* Calls semantic tokens, properties, states, responsive overrides.
|
|
37
|
+
*/
|
|
38
|
+
export declare function resolveIntent(intentName: string, options?: {
|
|
39
|
+
theme?: 'light' | 'dark' | 'high-contrast';
|
|
40
|
+
viewport?: string;
|
|
41
|
+
}): {
|
|
42
|
+
properties: Record<string, string | number>;
|
|
43
|
+
states: Record<string, Record<string, string | number>>;
|
|
44
|
+
responsive: Record<string, Record<string, string | number>>;
|
|
45
|
+
a11y: string[];
|
|
46
|
+
description: string;
|
|
47
|
+
} | null;
|
|
48
|
+
/**
|
|
49
|
+
* Get all available intents.
|
|
50
|
+
*/
|
|
51
|
+
export declare function getAvailableIntents(): string[];
|
|
52
|
+
/**
|
|
53
|
+
* Get intents by category.
|
|
54
|
+
*/
|
|
55
|
+
export declare function getIntentsByCategory(category: IntentDefinition['category']): string[];
|
|
56
|
+
/**
|
|
57
|
+
* Get a description of an intent.
|
|
58
|
+
*/
|
|
59
|
+
export declare function getIntentDescription(intentName: string): string | null;
|
|
60
|
+
/**
|
|
61
|
+
* Intent API IR pass.
|
|
62
|
+
* Resolves _intent metadata on rules into full component definitions.
|
|
63
|
+
*/
|
|
64
|
+
export declare const intentAPIPass: IRPass;
|
|
65
|
+
export declare const intentAPI: {
|
|
66
|
+
resolve: typeof resolveIntent;
|
|
67
|
+
list: typeof getAvailableIntents;
|
|
68
|
+
byCategory: typeof getIntentsByCategory;
|
|
69
|
+
description: typeof getIntentDescription;
|
|
70
|
+
catalog: Record<string, IntentDefinition>;
|
|
71
|
+
pass: IRPass;
|
|
72
|
+
};
|
|
73
|
+
export default intentAPI;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Layout Intelligence Engine
|
|
3
|
+
*
|
|
4
|
+
* Bidirectional pattern recognition:
|
|
5
|
+
* 1. EXPAND: Human shorthand → full CSS (via existing macros)
|
|
6
|
+
* 2. RECOGNIZE: Full CSS → detected pattern (NEW — this module)
|
|
7
|
+
* 3. COMPRESS: Duplicate patterns → shared intent suggestion
|
|
8
|
+
* 4. SUGGEST: Diagnostic when verbose CSS could be a macro
|
|
9
|
+
*/
|
|
10
|
+
import type { IRPass } from './style-ir.js';
|
|
11
|
+
export interface LayoutPattern {
|
|
12
|
+
/** Unique name of the pattern */
|
|
13
|
+
name: string;
|
|
14
|
+
/** Human-readable description */
|
|
15
|
+
description: string;
|
|
16
|
+
/** The macro call that generates this pattern */
|
|
17
|
+
macro: string;
|
|
18
|
+
/** Example usage */
|
|
19
|
+
example: string;
|
|
20
|
+
/** Properties that must match exactly */
|
|
21
|
+
required: Record<string, string | number>;
|
|
22
|
+
/** Properties that should be present but can have any value */
|
|
23
|
+
optional?: string[];
|
|
24
|
+
/** Minimum number of required matches to trigger recognition */
|
|
25
|
+
minMatches?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface PatternMatch {
|
|
28
|
+
pattern: LayoutPattern;
|
|
29
|
+
ruleId: string;
|
|
30
|
+
selector: string;
|
|
31
|
+
matchedProperties: string[];
|
|
32
|
+
confidence: number;
|
|
33
|
+
}
|
|
34
|
+
export interface PatternReport {
|
|
35
|
+
matches: PatternMatch[];
|
|
36
|
+
duplicates: Array<{
|
|
37
|
+
pattern: string;
|
|
38
|
+
selectors: string[];
|
|
39
|
+
count: number;
|
|
40
|
+
}>;
|
|
41
|
+
suggestions: Array<{
|
|
42
|
+
selector: string;
|
|
43
|
+
suggestion: string;
|
|
44
|
+
savings: number;
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Layout Intelligence IR pass.
|
|
49
|
+
* Scans all rules for known layout patterns, generates diagnostics and suggestions.
|
|
50
|
+
*/
|
|
51
|
+
export declare const layoutIntelligencePass: IRPass;
|
|
52
|
+
/**
|
|
53
|
+
* Analyze a set of declarations and return matching patterns.
|
|
54
|
+
*/
|
|
55
|
+
export declare function recognizeLayout(declarations: Record<string, string | number>): PatternMatch[];
|
|
56
|
+
/**
|
|
57
|
+
* Get the best macro for a set of declarations.
|
|
58
|
+
*/
|
|
59
|
+
export declare function suggestMacro(declarations: Record<string, string | number>): string | null;
|
|
60
|
+
/**
|
|
61
|
+
* Get all known layout patterns.
|
|
62
|
+
*/
|
|
63
|
+
export declare function getLayoutPatterns(): LayoutPattern[];
|
|
64
|
+
export declare const layoutIntelligence: {
|
|
65
|
+
recognize: typeof recognizeLayout;
|
|
66
|
+
suggestMacro: typeof suggestMacro;
|
|
67
|
+
getPatterns: typeof getLayoutPatterns;
|
|
68
|
+
pass: IRPass;
|
|
69
|
+
patterns: LayoutPattern[];
|
|
70
|
+
};
|
|
71
|
+
export default layoutIntelligence;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-Pass Optimization Pipeline
|
|
3
|
+
*
|
|
4
|
+
* Coordinates all compiler passes in a defined, deterministic order.
|
|
5
|
+
* Each pass is a pure function: StyleIR → StyleIR.
|
|
6
|
+
*
|
|
7
|
+
* Architecture inspired by: LLVM, Babel, SWC, Rust compiler
|
|
8
|
+
*
|
|
9
|
+
* Pipeline order (optimized for maximum information gain per pass):
|
|
10
|
+
* 1. Intent Recovery — fix typos, add defaults
|
|
11
|
+
* 2. Unit Resolution — resolve units, constant fold
|
|
12
|
+
* 3. Validation — contrast checks, conflict detection
|
|
13
|
+
* 4. Specificity Sorting — order rules by specificity
|
|
14
|
+
* 5. Dead Elimination — remove unused selectors
|
|
15
|
+
* 6. Atomic Extraction — extract shared properties
|
|
16
|
+
* 7. Media Query Packing — group same-query rules
|
|
17
|
+
* 8. CSS if() Transpiling — emit native if() + fallback
|
|
18
|
+
* 9. CSS Compression — minify output
|
|
19
|
+
* 10. Diagnostics Export — collect all pass diagnostics
|
|
20
|
+
*/
|
|
21
|
+
import type { StyleIR, IRPass } from './style-ir.js';
|
|
22
|
+
export type PassName = 'intent-recovery' | 'unit-resolution' | 'validation' | 'specificity-sort' | 'dead-elimination' | 'atomic-extraction' | 'media-query-packing' | 'css-if-transpile' | 'css-compression' | 'diagnostics-export';
|
|
23
|
+
export type PassPriority = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
|
|
24
|
+
export interface PassDefinition {
|
|
25
|
+
name: PassName;
|
|
26
|
+
priority: PassPriority;
|
|
27
|
+
description: string;
|
|
28
|
+
/** The actual transform function */
|
|
29
|
+
pass: IRPass;
|
|
30
|
+
/** Dependencies — these passes must run first */
|
|
31
|
+
requires: PassName[];
|
|
32
|
+
/** Whether this pass is enabled */
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface PassResult {
|
|
36
|
+
name: PassName;
|
|
37
|
+
duration: number;
|
|
38
|
+
nodesBefore: number;
|
|
39
|
+
nodesAfter: number;
|
|
40
|
+
changes: number;
|
|
41
|
+
errors: string[];
|
|
42
|
+
}
|
|
43
|
+
export interface PipelineResult {
|
|
44
|
+
ir: StyleIR;
|
|
45
|
+
css: string;
|
|
46
|
+
results: PassResult[];
|
|
47
|
+
totalDuration: number;
|
|
48
|
+
summary: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Pass 1: Intent Recovery
|
|
52
|
+
* Corrects typos, adds defaults for common patterns.
|
|
53
|
+
* Runs FIRST so all downstream passes see clean data.
|
|
54
|
+
*/
|
|
55
|
+
export declare const intentRecoveryPass: IRPass;
|
|
56
|
+
/**
|
|
57
|
+
* Pass 2: Unit Resolution
|
|
58
|
+
* Resolves math expressions, converts units where possible.
|
|
59
|
+
* Runs early so later passes see resolved values.
|
|
60
|
+
*/
|
|
61
|
+
export declare const unitResolutionPass: IRPass;
|
|
62
|
+
/**
|
|
63
|
+
* Pass 3: Validation
|
|
64
|
+
* Runs contrast checks, detects conflicts.
|
|
65
|
+
*/
|
|
66
|
+
export declare const validationPass: IRPass;
|
|
67
|
+
/**
|
|
68
|
+
* Pass 4: Specificity Sorting
|
|
69
|
+
* Orders rules by specificity so the cascade is predictable.
|
|
70
|
+
*/
|
|
71
|
+
export declare const specificitySortPass: IRPass;
|
|
72
|
+
/**
|
|
73
|
+
* Pass 5: Dead Elimination
|
|
74
|
+
* Removes rules marked as dead.
|
|
75
|
+
*/
|
|
76
|
+
export declare const deadEliminationPass: IRPass;
|
|
77
|
+
/**
|
|
78
|
+
* Pass 6: Atomic Extraction
|
|
79
|
+
* Identifies identical declarations across rules and marks them for atomic CSS.
|
|
80
|
+
*/
|
|
81
|
+
export declare const atomicExtractionPass: IRPass;
|
|
82
|
+
/**
|
|
83
|
+
* Pass 7: Media Query Packing
|
|
84
|
+
* Groups rules with the same media query together.
|
|
85
|
+
*/
|
|
86
|
+
export declare const mediaQueryPackingPass: IRPass;
|
|
87
|
+
/**
|
|
88
|
+
* Pass 8: CSS if() Transpile
|
|
89
|
+
* Detects conditional patterns and emits native CSS if().
|
|
90
|
+
*/
|
|
91
|
+
export declare const cssIfTranspilePass: IRPass;
|
|
92
|
+
/**
|
|
93
|
+
* Pass 9: CSS Compression
|
|
94
|
+
* Minifies the IR — shortens values, removes unnecessary data.
|
|
95
|
+
*/
|
|
96
|
+
export declare const cssCompressionPass: IRPass;
|
|
97
|
+
/**
|
|
98
|
+
* Pass 10: Diagnostics Export
|
|
99
|
+
* Collects all diagnostics from passes for reporting.
|
|
100
|
+
*/
|
|
101
|
+
export declare const diagnosticsExportPass: IRPass;
|
|
102
|
+
/**
|
|
103
|
+
* The default pass pipeline — runs all passes in optimal order.
|
|
104
|
+
*/
|
|
105
|
+
export declare const DEFAULT_PIPELINE: PassDefinition[];
|
|
106
|
+
export declare class PassManager {
|
|
107
|
+
private passes;
|
|
108
|
+
private results;
|
|
109
|
+
constructor(passes?: PassDefinition[]);
|
|
110
|
+
/**
|
|
111
|
+
* Validate that all pass dependencies are satisfied.
|
|
112
|
+
*/
|
|
113
|
+
private validateDependencies;
|
|
114
|
+
/**
|
|
115
|
+
* Topological sort passes by dependencies.
|
|
116
|
+
* Passes with no dependencies run first.
|
|
117
|
+
*/
|
|
118
|
+
private sortByDependencies;
|
|
119
|
+
/**
|
|
120
|
+
* Run the full pipeline on an IR.
|
|
121
|
+
*/
|
|
122
|
+
run(ir: StyleIR): PipelineResult;
|
|
123
|
+
/**
|
|
124
|
+
* Get results from the last run.
|
|
125
|
+
*/
|
|
126
|
+
getResults(): PassResult[];
|
|
127
|
+
/**
|
|
128
|
+
* Print a human-readable report of pass results.
|
|
129
|
+
*/
|
|
130
|
+
report(): string;
|
|
131
|
+
/**
|
|
132
|
+
* Add a custom pass to the pipeline.
|
|
133
|
+
*/
|
|
134
|
+
addPass(pass: PassDefinition): this;
|
|
135
|
+
/**
|
|
136
|
+
* Remove a pass by name.
|
|
137
|
+
*/
|
|
138
|
+
removePass(name: PassName): this;
|
|
139
|
+
/**
|
|
140
|
+
* Enable/disable a pass.
|
|
141
|
+
*/
|
|
142
|
+
setPassEnabled(name: PassName, enabled: boolean): this;
|
|
143
|
+
/**
|
|
144
|
+
* Get the list of pass names in execution order.
|
|
145
|
+
*/
|
|
146
|
+
getPassOrder(): PassName[];
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Run the default pipeline on an IR.
|
|
150
|
+
*/
|
|
151
|
+
export declare function runDefaultPipeline(ir: StyleIR): PipelineResult;
|
|
152
|
+
export declare const passManager: {
|
|
153
|
+
PassManager: typeof PassManager;
|
|
154
|
+
runDefaultPipeline: typeof runDefaultPipeline;
|
|
155
|
+
DEFAULT_PIPELINE: PassDefinition[];
|
|
156
|
+
};
|
|
157
|
+
export default passManager;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Style Pattern Learner
|
|
3
|
+
*
|
|
4
|
+
* Observes all styles across a codebase and:
|
|
5
|
+
* 1. DETECTS repeated patterns by content-hashing style blocks
|
|
6
|
+
* 2. RANKS by frequency × property count
|
|
7
|
+
* 3. SUGGESTS extraction as chain.recipe() or intent macros
|
|
8
|
+
* 4. REPORTS savings (lines eliminated, bundle size reduction)
|
|
9
|
+
*
|
|
10
|
+
* This is compiler-assisted design system extraction.
|
|
11
|
+
*/
|
|
12
|
+
import type { IRRule, IRPass } from './style-ir.js';
|
|
13
|
+
export interface StyleFingerprint {
|
|
14
|
+
/** Content hash of the property set */
|
|
15
|
+
hash: string;
|
|
16
|
+
/** Human-readable signature */
|
|
17
|
+
signature: string;
|
|
18
|
+
/** Properties and their values */
|
|
19
|
+
properties: Record<string, string | number>;
|
|
20
|
+
/** Number of properties */
|
|
21
|
+
propertyCount: number;
|
|
22
|
+
}
|
|
23
|
+
export interface PatternCluster {
|
|
24
|
+
/** The fingerprint that defines this cluster */
|
|
25
|
+
fingerprint: StyleFingerprint;
|
|
26
|
+
/** All rules that match this pattern */
|
|
27
|
+
occurrences: Array<{
|
|
28
|
+
ruleId: string;
|
|
29
|
+
selector: string;
|
|
30
|
+
sourceFile?: string;
|
|
31
|
+
component?: string;
|
|
32
|
+
}>;
|
|
33
|
+
/** How many times it appears */
|
|
34
|
+
frequency: number;
|
|
35
|
+
/** Across how many files */
|
|
36
|
+
fileCount: number;
|
|
37
|
+
/** Importance score (frequency × propertyCount) */
|
|
38
|
+
score: number;
|
|
39
|
+
/** Suggested recipe name */
|
|
40
|
+
suggestedName: string;
|
|
41
|
+
/** Suggested extraction as recipe */
|
|
42
|
+
suggestedRecipe: string;
|
|
43
|
+
/** Estimated savings */
|
|
44
|
+
savings: {
|
|
45
|
+
declarations: number;
|
|
46
|
+
linesEliminated: number;
|
|
47
|
+
bundleReduction: string;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export interface LearningReport {
|
|
51
|
+
clusters: PatternCluster[];
|
|
52
|
+
totalPatterns: number;
|
|
53
|
+
highValuePatterns: PatternCluster[];
|
|
54
|
+
totalSavings: {
|
|
55
|
+
declarations: number;
|
|
56
|
+
estimatedBytes: number;
|
|
57
|
+
};
|
|
58
|
+
summary: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Create a content hash from a set of declarations.
|
|
62
|
+
* Ignores selectors, focuses on the actual style properties.
|
|
63
|
+
*/
|
|
64
|
+
declare function fingerprintDeclarations(declarations: Array<{
|
|
65
|
+
property: string;
|
|
66
|
+
value: string | number;
|
|
67
|
+
}>): StyleFingerprint;
|
|
68
|
+
/**
|
|
69
|
+
* Cluster rules by their style fingerprint.
|
|
70
|
+
* Only considers rules with a minimum number of declarations.
|
|
71
|
+
*/
|
|
72
|
+
declare function clusterPatterns(rules: IRRule[], options?: {
|
|
73
|
+
minProperties?: number;
|
|
74
|
+
minFrequency?: number;
|
|
75
|
+
}): PatternCluster[];
|
|
76
|
+
/**
|
|
77
|
+
* Generate a full learning report from clustered patterns.
|
|
78
|
+
*/
|
|
79
|
+
declare function generateReport(clusters: PatternCluster[]): LearningReport;
|
|
80
|
+
/**
|
|
81
|
+
* Pattern Learning IR pass.
|
|
82
|
+
* Analyzes rules, clusters patterns, and adds diagnostics.
|
|
83
|
+
*/
|
|
84
|
+
export declare const patternLearningPass: IRPass;
|
|
85
|
+
/**
|
|
86
|
+
* Learn patterns from a set of style rules.
|
|
87
|
+
*/
|
|
88
|
+
export declare function learnPatterns(rules: Array<{
|
|
89
|
+
selector: string;
|
|
90
|
+
declarations: Record<string, string | number>;
|
|
91
|
+
sourceFile?: string;
|
|
92
|
+
}>, options?: {
|
|
93
|
+
minProperties?: number;
|
|
94
|
+
minFrequency?: number;
|
|
95
|
+
}): LearningReport;
|
|
96
|
+
/**
|
|
97
|
+
* Get the top patterns worth extracting.
|
|
98
|
+
*/
|
|
99
|
+
export declare function getExtractionCandidates(rules: Array<{
|
|
100
|
+
selector: string;
|
|
101
|
+
declarations: Record<string, string | number>;
|
|
102
|
+
sourceFile?: string;
|
|
103
|
+
}>, minScore?: number): PatternCluster[];
|
|
104
|
+
export declare const patternLearner: {
|
|
105
|
+
learn: typeof learnPatterns;
|
|
106
|
+
extract: typeof getExtractionCandidates;
|
|
107
|
+
fingerprint: typeof fingerprintDeclarations;
|
|
108
|
+
cluster: typeof clusterPatterns;
|
|
109
|
+
report: typeof generateReport;
|
|
110
|
+
pass: IRPass;
|
|
111
|
+
};
|
|
112
|
+
export default patternLearner;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatic Responsive Inference Engine
|
|
3
|
+
*
|
|
4
|
+
* Detects layout patterns that will break on mobile and suggests fixes.
|
|
5
|
+
* Positions ChainCSS as a layout advisor, not just a compiler.
|
|
6
|
+
*
|
|
7
|
+
* Detection rules:
|
|
8
|
+
* - Fixed widths > 768px → suggest min(100%, width)
|
|
9
|
+
* - Grid columns > 2 → suggest auto-fit
|
|
10
|
+
* - Large font sizes → suggest clamp()
|
|
11
|
+
* - Fixed height: 100vh → suggest 100dvh
|
|
12
|
+
* - Large padding/gap → suggest responsive reduction
|
|
13
|
+
* - Multiple fixed-width columns → suggest auto-fit grid
|
|
14
|
+
*/
|
|
15
|
+
import type { IRPass } from './style-ir.js';
|
|
16
|
+
export interface ResponsiveIssue {
|
|
17
|
+
ruleId: string;
|
|
18
|
+
selector: string;
|
|
19
|
+
property: string;
|
|
20
|
+
currentValue: string;
|
|
21
|
+
severity: 'error' | 'warning' | 'info';
|
|
22
|
+
category: 'overflow' | 'grid' | 'typography' | 'spacing' | 'viewport' | 'columns';
|
|
23
|
+
message: string;
|
|
24
|
+
suggestedFix: string;
|
|
25
|
+
autoFixAvailable: boolean;
|
|
26
|
+
affectedViewports: string[];
|
|
27
|
+
}
|
|
28
|
+
export interface ResponsiveReport {
|
|
29
|
+
issues: ResponsiveIssue[];
|
|
30
|
+
criticalCount: number;
|
|
31
|
+
warningCount: number;
|
|
32
|
+
infoCount: number;
|
|
33
|
+
summary: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Responsive Inference IR pass.
|
|
37
|
+
* Detects responsive issues and adds diagnostics with suggested fixes.
|
|
38
|
+
*/
|
|
39
|
+
export declare const responsiveInferencePass: IRPass;
|
|
40
|
+
/**
|
|
41
|
+
* Analyze declarations and return responsive issues.
|
|
42
|
+
*/
|
|
43
|
+
export declare function analyzeResponsive(selector: string, declarations: Record<string, string | number>): ResponsiveIssue[];
|
|
44
|
+
/**
|
|
45
|
+
* Generate a full responsive report.
|
|
46
|
+
*/
|
|
47
|
+
export declare function generateResponsiveReport(issues: ResponsiveIssue[]): ResponsiveReport;
|
|
48
|
+
/**
|
|
49
|
+
* Auto-fix a single responsive issue.
|
|
50
|
+
*/
|
|
51
|
+
export declare function autoFixIssue(issue: ResponsiveIssue): string;
|
|
52
|
+
/**
|
|
53
|
+
* Auto-fix all auto-fixable issues.
|
|
54
|
+
*/
|
|
55
|
+
export declare function autoFixAll(issues: ResponsiveIssue[]): string[];
|
|
56
|
+
export declare const responsiveInference: {
|
|
57
|
+
analyze: typeof analyzeResponsive;
|
|
58
|
+
report: typeof generateResponsiveReport;
|
|
59
|
+
autoFix: typeof autoFixIssue;
|
|
60
|
+
autoFixAll: typeof autoFixAll;
|
|
61
|
+
pass: IRPass;
|
|
62
|
+
};
|
|
63
|
+
export default responsiveInference;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic Token System
|
|
3
|
+
*
|
|
4
|
+
* Intent-based styling that maps semantic concepts to design tokens.
|
|
5
|
+
* Wraps the existing token system — both coexist.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* chain.surface('interactive') // → maps to background, color, border-radius
|
|
9
|
+
* chain.text('primary') // → maps to color, font-weight
|
|
10
|
+
* chain.elevation('floating') // → maps to box-shadow, z-index
|
|
11
|
+
* chain.state('hover') // → maps to hover pseudo-class
|
|
12
|
+
* chain.spacing('comfortable') // → maps to padding
|
|
13
|
+
*/
|
|
14
|
+
import type { IRPass } from './style-ir.js';
|
|
15
|
+
export type SurfaceIntent = 'interactive' | 'container' | 'overlay' | 'sheet' | 'tooltip' | 'input';
|
|
16
|
+
export type TextIntent = 'primary' | 'secondary' | 'muted' | 'link' | 'inverse' | 'code';
|
|
17
|
+
export type ElevationIntent = 'flat' | 'raised' | 'floating' | 'sticky' | 'overlay' | 'modal';
|
|
18
|
+
export type StateIntent = 'hover' | 'active' | 'focus' | 'disabled' | 'loading' | 'selected';
|
|
19
|
+
export type SpacingIntent = 'none' | 'tight' | 'compact' | 'comfortable' | 'spacious' | 'generous';
|
|
20
|
+
export interface SemanticMapping {
|
|
21
|
+
properties: Record<string, string | number>;
|
|
22
|
+
pseudoClass?: string;
|
|
23
|
+
description: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ThemeContext {
|
|
26
|
+
mode: 'light' | 'dark' | 'high-contrast';
|
|
27
|
+
brand?: Record<string, string>;
|
|
28
|
+
containerContext?: 'light' | 'dark';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Resolve a semantic intent to concrete CSS properties.
|
|
32
|
+
* Applies theme overrides based on context.
|
|
33
|
+
*/
|
|
34
|
+
export declare function resolveSemantic(category: 'surface' | 'text' | 'elevation' | 'state' | 'spacing', intent: string, themeContext?: ThemeContext): SemanticMapping | null;
|
|
35
|
+
/**
|
|
36
|
+
* Get all available intents for a category.
|
|
37
|
+
*/
|
|
38
|
+
export declare function getSemanticIntents(category: 'surface' | 'text' | 'elevation' | 'state' | 'spacing'): string[];
|
|
39
|
+
/**
|
|
40
|
+
* Get the description of a semantic intent.
|
|
41
|
+
*/
|
|
42
|
+
export declare function getSemanticDescription(category: 'surface' | 'text' | 'elevation' | 'state' | 'spacing', intent: string): string | null;
|
|
43
|
+
/**
|
|
44
|
+
* Semantic Token IR pass.
|
|
45
|
+
* Resolves any _semantic metadata on rules into concrete declarations.
|
|
46
|
+
*/
|
|
47
|
+
export declare const semanticTokensPass: IRPass;
|
|
48
|
+
export declare const semanticTokens: {
|
|
49
|
+
resolve: typeof resolveSemantic;
|
|
50
|
+
getIntents: typeof getSemanticIntents;
|
|
51
|
+
getDescription: typeof getSemanticDescription;
|
|
52
|
+
pass: IRPass;
|
|
53
|
+
theme: Record<string, Record<string, SemanticMapping>>;
|
|
54
|
+
darkOverrides: Record<string, Record<string, Partial<Record<string, string | number>>>>;
|
|
55
|
+
highContrastOverrides: Record<string, Record<string, Partial<Record<string, string | number>>>>;
|
|
56
|
+
};
|
|
57
|
+
export default semanticTokens;
|