chaincss 2.1.39 → 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/css-if-transpiler.d.ts +33 -0
- package/dist/compiler/design-orchestrator.d.ts +119 -0
- package/dist/compiler/intent-api.d.ts +73 -0
- package/dist/compiler/intent-engine.d.ts +19 -1
- 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/scroll-timeline.d.ts +91 -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 +23 -0
- package/dist/index.js +4126 -2
- package/package.json +1 -1
- package/src/compiler/accessibility-engine.ts +502 -0
- package/src/compiler/constraint-solver.ts +407 -0
- package/src/compiler/css-if-transpiler.ts +117 -0
- package/src/compiler/design-orchestrator.ts +322 -0
- package/src/compiler/intent-api.ts +505 -0
- package/src/compiler/intent-engine.ts +291 -1
- 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/scroll-timeline.ts +284 -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 +209 -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,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS if() Transpiler
|
|
3
|
+
* Detects conditional style patterns and emits:
|
|
4
|
+
* 1. Native CSS if() — Chrome 137+
|
|
5
|
+
* 2. @supports fallback — Firefox, Safari
|
|
6
|
+
*/
|
|
7
|
+
export interface IfCondition {
|
|
8
|
+
property: string;
|
|
9
|
+
variable: string;
|
|
10
|
+
conditions: Record<string, string | number>;
|
|
11
|
+
defaultValue: string | number;
|
|
12
|
+
}
|
|
13
|
+
export interface DetectedCondition {
|
|
14
|
+
property: string;
|
|
15
|
+
variable: string;
|
|
16
|
+
conditions: Record<string, string | number>;
|
|
17
|
+
defaultValue: string | number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Detect conditional patterns from _conditions metadata.
|
|
21
|
+
* When chain.when() branches set the same property to different values,
|
|
22
|
+
* those can be compiled to CSS if().
|
|
23
|
+
*/
|
|
24
|
+
export declare function detectIfPatterns(styles: Record<string, any>): DetectedCondition[];
|
|
25
|
+
/**
|
|
26
|
+
* Generate CSS if() output for detected conditions.
|
|
27
|
+
*/
|
|
28
|
+
export declare function emitCSSIf(selector: string, detectedConditions: DetectedCondition[], baseProperties?: Record<string, string | number>): string;
|
|
29
|
+
declare const _default: {
|
|
30
|
+
detectIfPatterns: typeof detectIfPatterns;
|
|
31
|
+
emitCSSIf: typeof emitCSSIf;
|
|
32
|
+
};
|
|
33
|
+
export default _default;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Design System Orchestrator
|
|
3
|
+
*
|
|
4
|
+
* 1. WCAG Contrast Ratio Checker — validates text/background combos at build time
|
|
5
|
+
* 2. Contextual Tokens — tokens that auto-flip based on container context
|
|
6
|
+
* 3. Token Relationship Validator — ensures design tokens are consistent
|
|
7
|
+
*/
|
|
8
|
+
export interface ContrastResult {
|
|
9
|
+
foreground: string;
|
|
10
|
+
background: string;
|
|
11
|
+
ratio: number;
|
|
12
|
+
passes: {
|
|
13
|
+
AA: boolean;
|
|
14
|
+
AALarge: boolean;
|
|
15
|
+
AAA: boolean;
|
|
16
|
+
AAALarge: boolean;
|
|
17
|
+
};
|
|
18
|
+
suggestion?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ContrastReport {
|
|
21
|
+
checks: ContrastResult[];
|
|
22
|
+
failures: ContrastResult[];
|
|
23
|
+
warnings: ContrastResult[];
|
|
24
|
+
passCount: number;
|
|
25
|
+
failCount: number;
|
|
26
|
+
summary: string;
|
|
27
|
+
}
|
|
28
|
+
export interface ContextualToken {
|
|
29
|
+
name: string;
|
|
30
|
+
default: string;
|
|
31
|
+
contexts: Record<string, string>;
|
|
32
|
+
}
|
|
33
|
+
export interface TokenContext {
|
|
34
|
+
name: string;
|
|
35
|
+
parentSelector?: string;
|
|
36
|
+
tokens: Record<string, any>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Parse CSS color to RGBA components.
|
|
40
|
+
* Supports: hex, rgb(), rgba(), named colors
|
|
41
|
+
*/
|
|
42
|
+
declare function parseColor(color: string): {
|
|
43
|
+
r: number;
|
|
44
|
+
g: number;
|
|
45
|
+
b: number;
|
|
46
|
+
a: number;
|
|
47
|
+
} | null;
|
|
48
|
+
/**
|
|
49
|
+
* Calculate WCAG contrast ratio between two colors.
|
|
50
|
+
* Returns value between 1 (no contrast) and 21 (max contrast).
|
|
51
|
+
*/
|
|
52
|
+
export declare function contrastRatio(foreground: string, background: string): number;
|
|
53
|
+
/**
|
|
54
|
+
* Check WCAG compliance levels.
|
|
55
|
+
* AA: 4.5:1 normal, 3:1 large text
|
|
56
|
+
* AAA: 7:1 normal, 4.5:1 large text
|
|
57
|
+
*/
|
|
58
|
+
export declare function checkContrast(foreground: string, background: string): ContrastResult;
|
|
59
|
+
/**
|
|
60
|
+
* Run contrast checks across a set of style definitions.
|
|
61
|
+
*/
|
|
62
|
+
export declare function auditContrast(styles: Array<{
|
|
63
|
+
selector: string;
|
|
64
|
+
color: string;
|
|
65
|
+
backgroundColor: string;
|
|
66
|
+
}>): ContrastReport;
|
|
67
|
+
/**
|
|
68
|
+
* Contextual tokens that auto-resolve based on parent container.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* const buttonText = contextualToken({
|
|
72
|
+
* default: '#1a1a1a',
|
|
73
|
+
* contexts: {
|
|
74
|
+
* '.dark-section': '#ffffff',
|
|
75
|
+
* '.hero': '#ffffff',
|
|
76
|
+
* },
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* resolveContextual(buttonText, '.dark-section .my-button')
|
|
80
|
+
* // => '#ffffff'
|
|
81
|
+
*/
|
|
82
|
+
export declare function createContextualToken(defaultValue: string, contexts?: Record<string, string>): ContextualToken;
|
|
83
|
+
/**
|
|
84
|
+
* Resolve a contextual token based on the current selector path.
|
|
85
|
+
* Matches the most specific context that applies.
|
|
86
|
+
*/
|
|
87
|
+
export declare function resolveContextual(token: ContextualToken, selectorPath: string): string;
|
|
88
|
+
/**
|
|
89
|
+
* Generate CSS custom property fallback for contextual tokens.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* generateContextualCSS('button-text', contextualToken)
|
|
93
|
+
* // => "
|
|
94
|
+
* // .my-button { --button-text: #1a1a1a; }
|
|
95
|
+
* // .dark-section .my-button { --button-text: #ffffff; }
|
|
96
|
+
* // "
|
|
97
|
+
*/
|
|
98
|
+
export declare function generateContextualCSS(propertyName: string, token: ContextualToken, baseSelector: string): string;
|
|
99
|
+
/**
|
|
100
|
+
* Validate that token references are consistent.
|
|
101
|
+
* E.g., "primary" should have both foreground and background variants
|
|
102
|
+
* that contrast well with each other.
|
|
103
|
+
*/
|
|
104
|
+
export declare function validateTokenRelationships(tokens: Record<string, any>, pairs: Array<{
|
|
105
|
+
foreground: string;
|
|
106
|
+
background: string;
|
|
107
|
+
label: string;
|
|
108
|
+
}>): ContrastReport;
|
|
109
|
+
export declare const orchestrator: {
|
|
110
|
+
contrastRatio: typeof contrastRatio;
|
|
111
|
+
checkContrast: typeof checkContrast;
|
|
112
|
+
auditContrast: typeof auditContrast;
|
|
113
|
+
createContextualToken: typeof createContextualToken;
|
|
114
|
+
resolveContextual: typeof resolveContextual;
|
|
115
|
+
generateContextualCSS: typeof generateContextualCSS;
|
|
116
|
+
validateTokenRelationships: typeof validateTokenRelationships;
|
|
117
|
+
parseColor: typeof parseColor;
|
|
118
|
+
};
|
|
119
|
+
export default orchestrator;
|
|
@@ -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;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CorrectionResult, HealMode, HealResult, IntentContext } from '../core/types.js';
|
|
2
|
+
import { detectIfPatterns, emitCSSIf } from './css-if-transpiler.js';
|
|
2
3
|
export type { CorrectionResult, HealMode, HealResult, IntentContext };
|
|
3
4
|
interface ValueCorrection {
|
|
4
5
|
wrong: string;
|
|
@@ -15,11 +16,24 @@ export declare const intent: {
|
|
|
15
16
|
};
|
|
16
17
|
getCorrections(property: string): ValueCorrection[];
|
|
17
18
|
explain(correction: CorrectionResult): string;
|
|
18
|
-
|
|
19
|
+
cssIf: {
|
|
20
|
+
detect: typeof detectIfPatterns;
|
|
21
|
+
emit: typeof emitCSSIf;
|
|
22
|
+
};
|
|
19
23
|
getIntents(): {
|
|
20
24
|
pattern: string;
|
|
21
25
|
description: string;
|
|
22
26
|
}[];
|
|
27
|
+
getKnownProperties(): string[];
|
|
28
|
+
macro(name: string): Record<string, any> | null;
|
|
29
|
+
getMacros(): string[];
|
|
30
|
+
getMacroDescription(name: string): string | null;
|
|
31
|
+
hasMacro(name: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Apply a layout macro to an existing styles object.
|
|
34
|
+
* Merges macro properties with user overrides.
|
|
35
|
+
*/
|
|
36
|
+
applyMacro(name: string, overrides?: Record<string, any>): Record<string, any> | null;
|
|
23
37
|
};
|
|
24
38
|
export declare const correct: (property: string, value: string, context?: IntentContext) => CorrectionResult | null;
|
|
25
39
|
export declare const heal: (styles: Record<string, any>, mode?: HealMode, context?: IntentContext) => HealResult;
|
|
@@ -28,4 +42,8 @@ export declare const validate: (property: string, value: string) => {
|
|
|
28
42
|
suggestion?: string;
|
|
29
43
|
};
|
|
30
44
|
export declare const getIntent: (value: string, ctx?: IntentContext) => string | null;
|
|
45
|
+
export declare const macro: (name: string) => Record<string, any> | null;
|
|
46
|
+
export declare const applyMacro: (name: string, overrides?: Record<string, any>) => Record<string, any> | null;
|
|
47
|
+
export declare const getMacros: () => string[];
|
|
48
|
+
export declare const hasMacro: (name: string) => boolean;
|
|
31
49
|
export default intent;
|
|
@@ -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;
|