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
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// src/compiler/intent-engine.ts
|
|
2
|
+
|
|
2
3
|
import type { CorrectionResult, HealMode, HealResult, IntentContext } from '../core/types.js';
|
|
4
|
+
import { detectIfPatterns, emitCSSIf } from './css-if-transpiler.js';
|
|
3
5
|
export type { CorrectionResult, HealMode, HealResult, IntentContext };
|
|
4
6
|
|
|
5
7
|
interface ValueCorrection { wrong: string; correct: string; confidence: number; }
|
|
@@ -13,6 +15,262 @@ const SEMANTIC_INTENTS: Array<{pattern: RegExp; handler: Function; description:
|
|
|
13
15
|
{ pattern: /^(rounded|round)$/i, handler: (v: string, ctx: any) => ({ original: v, property: ctx.property||'border-radius', corrected: '9999px', defaults: { borderRadius: '9999px' }, confidence: 0.8, intent: 'rounded-pill', explanation: '"rounded" -> border-radius: 9999px (pill)' }), description: 'rounded -> pill' },
|
|
14
16
|
];
|
|
15
17
|
|
|
18
|
+
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// Layout Macros — High-level semantic intents
|
|
21
|
+
// These compile complex multi-property layouts from simple intent names
|
|
22
|
+
// ============================================================================
|
|
23
|
+
|
|
24
|
+
interface LayoutMacro {
|
|
25
|
+
name: string;
|
|
26
|
+
description: string;
|
|
27
|
+
properties: Record<string, string | number>;
|
|
28
|
+
defaults?: Record<string, string | number>;
|
|
29
|
+
mediaQueries?: Record<string, Record<string, any>>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const LAYOUT_MACROS: Record<string, LayoutMacro> = {
|
|
33
|
+
stickyHeader: {
|
|
34
|
+
name: 'stickyHeader',
|
|
35
|
+
description: 'Sticky header with scroll shadow and entrance animation',
|
|
36
|
+
properties: {
|
|
37
|
+
position: 'sticky',
|
|
38
|
+
top: '0',
|
|
39
|
+
zIndex: '50',
|
|
40
|
+
backgroundColor: 'var(--header-bg, white)',
|
|
41
|
+
backdropFilter: 'blur(8px)',
|
|
42
|
+
borderBottom: '1px solid transparent',
|
|
43
|
+
},
|
|
44
|
+
defaults: {
|
|
45
|
+
'--header-bg': 'white',
|
|
46
|
+
'--header-shadow': '0 4px 12px rgba(0,0,0,0.1)',
|
|
47
|
+
},
|
|
48
|
+
mediaQueries: {
|
|
49
|
+
'(max-width: 768px)': {
|
|
50
|
+
padding: '12px 16px',
|
|
51
|
+
},
|
|
52
|
+
'(min-width: 769px)': {
|
|
53
|
+
padding: '16px 32px',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
card: {
|
|
59
|
+
name: 'card',
|
|
60
|
+
description: 'Standard card container with hover lift effect',
|
|
61
|
+
properties: {
|
|
62
|
+
display: 'flex',
|
|
63
|
+
flexDirection: 'column',
|
|
64
|
+
borderRadius: '12px',
|
|
65
|
+
backgroundColor: 'var(--card-bg, white)',
|
|
66
|
+
boxShadow: '0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08)',
|
|
67
|
+
transition: 'box-shadow 0.2s ease, transform 0.2s ease',
|
|
68
|
+
overflow: 'hidden',
|
|
69
|
+
},
|
|
70
|
+
defaults: {
|
|
71
|
+
'--card-bg': 'white',
|
|
72
|
+
'--card-hover-shadow': '0 10px 30px rgba(0,0,0,0.15)',
|
|
73
|
+
},
|
|
74
|
+
mediaQueries: {
|
|
75
|
+
'(hover: hover)': {
|
|
76
|
+
'&:hover': {
|
|
77
|
+
boxShadow: 'var(--card-hover-shadow)',
|
|
78
|
+
transform: 'translateY(-2px)',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
hero: {
|
|
85
|
+
name: 'hero',
|
|
86
|
+
description: 'Full-width hero section with centered content',
|
|
87
|
+
properties: {
|
|
88
|
+
display: 'flex',
|
|
89
|
+
flexDirection: 'column',
|
|
90
|
+
justifyContent: 'center',
|
|
91
|
+
alignItems: 'center',
|
|
92
|
+
width: '100%',
|
|
93
|
+
minHeight: '60vh',
|
|
94
|
+
padding: '48px 24px',
|
|
95
|
+
textAlign: 'center',
|
|
96
|
+
},
|
|
97
|
+
defaults: {},
|
|
98
|
+
mediaQueries: {
|
|
99
|
+
'(max-width: 768px)': {
|
|
100
|
+
minHeight: '40vh',
|
|
101
|
+
padding: '32px 16px',
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
container: {
|
|
107
|
+
name: 'container',
|
|
108
|
+
description: 'Responsive centered container with max-width',
|
|
109
|
+
properties: {
|
|
110
|
+
width: '100%',
|
|
111
|
+
maxWidth: '1200px',
|
|
112
|
+
marginLeft: 'auto',
|
|
113
|
+
marginRight: 'auto',
|
|
114
|
+
paddingLeft: '16px',
|
|
115
|
+
paddingRight: '16px',
|
|
116
|
+
},
|
|
117
|
+
defaults: {},
|
|
118
|
+
mediaQueries: {
|
|
119
|
+
'(min-width: 768px)': {
|
|
120
|
+
paddingLeft: '24px',
|
|
121
|
+
paddingRight: '24px',
|
|
122
|
+
},
|
|
123
|
+
'(min-width: 1024px)': {
|
|
124
|
+
paddingLeft: '32px',
|
|
125
|
+
paddingRight: '32px',
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
center: {
|
|
131
|
+
name: 'center',
|
|
132
|
+
description: 'Absolute centering using flexbox',
|
|
133
|
+
properties: {
|
|
134
|
+
display: 'flex',
|
|
135
|
+
justifyContent: 'center',
|
|
136
|
+
alignItems: 'center',
|
|
137
|
+
},
|
|
138
|
+
defaults: {},
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
gridList: {
|
|
142
|
+
name: 'gridList',
|
|
143
|
+
description: 'Responsive grid list with auto-fit columns',
|
|
144
|
+
properties: {
|
|
145
|
+
display: 'grid',
|
|
146
|
+
gridTemplateColumns: 'repeat(auto-fit, minmax(280px, 1fr))',
|
|
147
|
+
gap: '24px',
|
|
148
|
+
},
|
|
149
|
+
defaults: {},
|
|
150
|
+
mediaQueries: {
|
|
151
|
+
'(max-width: 640px)': {
|
|
152
|
+
gridTemplateColumns: '1fr',
|
|
153
|
+
gap: '16px',
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
sidebar: {
|
|
159
|
+
name: 'sidebar',
|
|
160
|
+
description: 'Two-column layout: sidebar + main content',
|
|
161
|
+
properties: {
|
|
162
|
+
display: 'grid',
|
|
163
|
+
gridTemplateColumns: '280px 1fr',
|
|
164
|
+
gap: '32px',
|
|
165
|
+
minHeight: '100vh',
|
|
166
|
+
},
|
|
167
|
+
defaults: {},
|
|
168
|
+
mediaQueries: {
|
|
169
|
+
'(max-width: 1024px)': {
|
|
170
|
+
gridTemplateColumns: '1fr',
|
|
171
|
+
gap: '24px',
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
pill: {
|
|
177
|
+
name: 'pill',
|
|
178
|
+
description: 'Pill-shaped element (fully rounded)',
|
|
179
|
+
properties: {
|
|
180
|
+
borderRadius: '9999px',
|
|
181
|
+
padding: '8px 20px',
|
|
182
|
+
display: 'inline-flex',
|
|
183
|
+
alignItems: 'center',
|
|
184
|
+
justifyContent: 'center',
|
|
185
|
+
},
|
|
186
|
+
defaults: {},
|
|
187
|
+
},
|
|
188
|
+
|
|
189
|
+
glass: {
|
|
190
|
+
name: 'glass',
|
|
191
|
+
description: 'Frosted glass morphism effect',
|
|
192
|
+
properties: {
|
|
193
|
+
backgroundColor: 'rgba(255, 255, 255, 0.1)',
|
|
194
|
+
backdropFilter: 'blur(16px)',
|
|
195
|
+
border: '1px solid rgba(255, 255, 255, 0.2)',
|
|
196
|
+
borderRadius: '16px',
|
|
197
|
+
},
|
|
198
|
+
defaults: {},
|
|
199
|
+
},
|
|
200
|
+
|
|
201
|
+
truncate: {
|
|
202
|
+
name: 'truncate',
|
|
203
|
+
description: 'Single-line text truncation with ellipsis',
|
|
204
|
+
properties: {
|
|
205
|
+
overflow: 'hidden',
|
|
206
|
+
textOverflow: 'ellipsis',
|
|
207
|
+
whiteSpace: 'nowrap',
|
|
208
|
+
},
|
|
209
|
+
defaults: {},
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
srOnly: {
|
|
213
|
+
name: 'srOnly',
|
|
214
|
+
description: 'Screen-reader only (visually hidden but accessible)',
|
|
215
|
+
properties: {
|
|
216
|
+
position: 'absolute',
|
|
217
|
+
width: '1px',
|
|
218
|
+
height: '1px',
|
|
219
|
+
padding: '0',
|
|
220
|
+
margin: '-1px',
|
|
221
|
+
overflow: 'hidden',
|
|
222
|
+
clip: 'rect(0, 0, 0, 0)',
|
|
223
|
+
whiteSpace: 'nowrap',
|
|
224
|
+
borderWidth: '0',
|
|
225
|
+
},
|
|
226
|
+
defaults: {},
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// ============================================================================
|
|
231
|
+
// Layout Macro Resolver
|
|
232
|
+
// ============================================================================
|
|
233
|
+
|
|
234
|
+
function resolveLayoutMacro(name: string): LayoutMacro | null {
|
|
235
|
+
return LAYOUT_MACROS[name] || null;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function expandLayoutMacro(name: string): Record<string, any> | null {
|
|
239
|
+
const macro = resolveLayoutMacro(name);
|
|
240
|
+
if (!macro) return null;
|
|
241
|
+
|
|
242
|
+
// Start with properties
|
|
243
|
+
const result: Record<string, any> = { ...macro.properties };
|
|
244
|
+
|
|
245
|
+
// Merge defaults (CSS custom properties) into the result
|
|
246
|
+
if (macro.defaults) {
|
|
247
|
+
Object.assign(result, macro.defaults);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Apply media queries as nested atRules
|
|
251
|
+
if (macro.mediaQueries) {
|
|
252
|
+
result.atRules = result.atRules || [];
|
|
253
|
+
for (const [query, props] of Object.entries(macro.mediaQueries)) {
|
|
254
|
+
result.atRules.push({
|
|
255
|
+
type: 'media',
|
|
256
|
+
query,
|
|
257
|
+
styles: props,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return result;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function getAvailableMacros(): string[] {
|
|
266
|
+
return Object.keys(LAYOUT_MACROS);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function getMacroDescription(name: string): string | null {
|
|
270
|
+
const macro = resolveLayoutMacro(name);
|
|
271
|
+
return macro?.description || null;
|
|
272
|
+
}
|
|
273
|
+
|
|
16
274
|
const VALUE_CORRECTIONS: Record<string, ValueCorrection[]> = {
|
|
17
275
|
'display': [{wrong:'flexbox',correct:'flex',confidence:0.95},{wrong:'inline-flexbox',correct:'inline-flex',confidence:0.95}],
|
|
18
276
|
'position': [{wrong:'abs',correct:'absolute',confidence:0.9},{wrong:'rel',correct:'relative',confidence:0.9}],
|
|
@@ -101,12 +359,44 @@ export const intent = {
|
|
|
101
359
|
},
|
|
102
360
|
getCorrections(property: string): ValueCorrection[] { return VALUE_CORRECTIONS[property] || []; },
|
|
103
361
|
explain(correction: CorrectionResult): string { return correction.explanation; },
|
|
104
|
-
|
|
362
|
+
cssIf: { detect: detectIfPatterns, emit: emitCSSIf },
|
|
105
363
|
getIntents() { return SEMANTIC_INTENTS.map(r => ({ pattern: r.pattern.toString(), description: r.description })); },
|
|
364
|
+
getKnownProperties(): string[] { return [...KNOWN_PROPERTIES]; },
|
|
365
|
+
|
|
366
|
+
// Layout Macros
|
|
367
|
+
macro(name: string): Record<string, any> | null { return expandLayoutMacro(name); },
|
|
368
|
+
getMacros(): string[] { return getAvailableMacros(); },
|
|
369
|
+
getMacroDescription(name: string): string | null { return getMacroDescription(name); },
|
|
370
|
+
hasMacro(name: string): boolean { return name in LAYOUT_MACROS; },
|
|
371
|
+
/**
|
|
372
|
+
* Apply a layout macro to an existing styles object.
|
|
373
|
+
* Merges macro properties with user overrides.
|
|
374
|
+
*/
|
|
375
|
+
applyMacro(name: string, overrides?: Record<string, any>): Record<string, any> | null {
|
|
376
|
+
const macro = expandLayoutMacro(name);
|
|
377
|
+
if (!macro) return null;
|
|
378
|
+
if (!overrides) return macro;
|
|
379
|
+
// Deep merge: user overrides win
|
|
380
|
+
const merged = { ...macro };
|
|
381
|
+
for (const [key, value] of Object.entries(overrides)) {
|
|
382
|
+
if (key === 'atRules' && Array.isArray(value) && Array.isArray(merged.atRules)) {
|
|
383
|
+
merged.atRules = [...merged.atRules, ...value];
|
|
384
|
+
} else if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
385
|
+
merged[key] = { ...(merged[key] || {}), ...value };
|
|
386
|
+
} else {
|
|
387
|
+
merged[key] = value;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return merged;
|
|
391
|
+
},
|
|
106
392
|
};
|
|
107
393
|
|
|
108
394
|
export const correct = intent.correct.bind(intent);
|
|
109
395
|
export const heal = intent.heal.bind(intent);
|
|
110
396
|
export const validate = intent.validate.bind(intent);
|
|
111
397
|
export const getIntent = intent.getIntent.bind(intent);
|
|
398
|
+
export const macro = intent.macro.bind(intent);
|
|
399
|
+
export const applyMacro = intent.applyMacro.bind(intent);
|
|
400
|
+
export const getMacros = intent.getMacros.bind(intent);
|
|
401
|
+
export const hasMacro = intent.hasMacro.bind(intent);
|
|
112
402
|
export default intent;
|