chaincss 2.1.38 → 2.2.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.
@@ -0,0 +1,49 @@
1
+ import type { CorrectionResult, HealMode, HealResult, IntentContext } from '../core/types.js';
2
+ import { detectIfPatterns, emitCSSIf } from './css-if-transpiler.js';
3
+ export type { CorrectionResult, HealMode, HealResult, IntentContext };
4
+ interface ValueCorrection {
5
+ wrong: string;
6
+ correct: string;
7
+ confidence: number;
8
+ }
9
+ export declare const intent: {
10
+ correct(property: string, value: string, context?: IntentContext): CorrectionResult | null;
11
+ heal(styles: Record<string, any>, mode?: HealMode, context?: IntentContext): HealResult;
12
+ getIntent(value: string, ctx?: IntentContext): string | null;
13
+ validate(property: string, value: string): {
14
+ valid: boolean;
15
+ suggestion?: string;
16
+ };
17
+ getCorrections(property: string): ValueCorrection[];
18
+ explain(correction: CorrectionResult): string;
19
+ cssIf: {
20
+ detect: typeof detectIfPatterns;
21
+ emit: typeof emitCSSIf;
22
+ };
23
+ getIntents(): {
24
+ pattern: string;
25
+ description: string;
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;
37
+ };
38
+ export declare const correct: (property: string, value: string, context?: IntentContext) => CorrectionResult | null;
39
+ export declare const heal: (styles: Record<string, any>, mode?: HealMode, context?: IntentContext) => HealResult;
40
+ export declare const validate: (property: string, value: string) => {
41
+ valid: boolean;
42
+ suggestion?: string;
43
+ };
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;
49
+ export default intent;
@@ -0,0 +1,89 @@
1
+ import type { CSSUnit, CSSMathValue, MathContext, MathResult, FluidTypeConfig } from '../core/types.js';
2
+ export type { CSSUnit, CSSMathValue, MathContext, MathResult, FluidTypeConfig };
3
+ export type MathOp = 'add' | 'subtract' | 'multiply' | 'divide';
4
+ export declare const math: {
5
+ /**
6
+ * Add two CSS values with unit resolution.
7
+ *
8
+ * @example
9
+ * math.add('10px', '2rem') // → '42px' (with default context)
10
+ * math.add('10px', '2rem', { rootFontSize: 16 }) // → '42px'
11
+ * math.add('10px', '2vw') // → 'calc(10px + 2vw)'
12
+ */
13
+ add(a: string | number, b: string | number, context?: MathContext): MathResult;
14
+ /**
15
+ * Subtract two CSS values with unit resolution.
16
+ */
17
+ subtract(a: string | number, b: string | number, context?: MathContext): MathResult;
18
+ /**
19
+ * Multiply two CSS values with unit resolution.
20
+ */
21
+ multiply(a: string | number, b: string | number, context?: MathContext): MathResult;
22
+ /**
23
+ * Divide two CSS values with unit resolution.
24
+ */
25
+ divide(a: string | number, b: string | number, context?: MathContext): MathResult;
26
+ /**
27
+ * Sum multiple CSS values.
28
+ */
29
+ sum(...values: (string | number)[]): MathResult;
30
+ /**
31
+ * Resolve a CSS value to pixels.
32
+ */
33
+ toPx(value: string | number, context?: MathContext): number;
34
+ /**
35
+ * Convert between CSS units.
36
+ */
37
+ convert(value: string | number, toUnit: CSSUnit, context?: MathContext): MathResult;
38
+ /**
39
+ * Create a fluid typography clamp() expression.
40
+ *
41
+ * @example
42
+ * math.fluidType({ minSize: 14, maxSize: 20 })
43
+ * // → 'clamp(14px, 0.625vw + 12px, 20px)'
44
+ * math.fluidType({ minSize: 14, maxSize: 20, unit: 'rem', rootFontSize: 16 })
45
+ * // → 'clamp(0.875rem, 0.625vw + 0.75rem, 1.25rem)'
46
+ */
47
+ fluidType(config: FluidTypeConfig): MathResult;
48
+ /**
49
+ * Scale a value by a factor with unit preservation.
50
+ */
51
+ scale(value: string | number, factor: number): MathResult;
52
+ /**
53
+ * Clamp a CSS value between min and max.
54
+ */
55
+ clampValue(value: string | number, min: string | number, max: string | number, context?: MathContext): MathResult;
56
+ /**
57
+ * Parse a CSS value into its numeric and unit parts.
58
+ */
59
+ parse(value: string | number): CSSMathValue;
60
+ /**
61
+ * Check if two values have compatible units for direct operations.
62
+ */
63
+ compatible(a: string | number, b: string | number): boolean;
64
+ /**
65
+ * Get the category of a CSS unit.
66
+ */
67
+ unitCategory(unit: CSSUnit): string;
68
+ /**
69
+ * Create a CSS min() expression.
70
+ */
71
+ cssMin(...values: (string | number)[]): string;
72
+ /**
73
+ * Create a CSS max() expression.
74
+ */
75
+ cssMax(...values: (string | number)[]): string;
76
+ /**
77
+ * Format a number with specified precision.
78
+ */
79
+ precision(value: number, decimals?: number): string;
80
+ };
81
+ export declare const add: (a: string | number, b: string | number, context?: MathContext) => MathResult;
82
+ export declare const subtract: (a: string | number, b: string | number, context?: MathContext) => MathResult;
83
+ export declare const multiply: (a: string | number, b: string | number, context?: MathContext) => MathResult;
84
+ export declare const divide: (a: string | number, b: string | number, context?: MathContext) => MathResult;
85
+ export declare const fluidType: (config: FluidTypeConfig) => MathResult;
86
+ export declare const convert: (value: string | number, toUnit: CSSUnit, context?: MathContext) => MathResult;
87
+ export declare const toPx: (value: string | number, context?: MathContext) => number;
88
+ export declare const scale: (value: string | number, factor: number) => MathResult;
89
+ export default math;
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Scroll-Driven Animations Engine
3
+ *
4
+ * Compiles timeline-based animation descriptions into:
5
+ * 1. Native CSS scroll-timeline / view-timeline (Chromium 115+)
6
+ * 2. @supports fallback with JavaScript polyfill hint
7
+ *
8
+ * API inspiration: GSAP's ScrollTrigger, but compiles to 0kb JS.
9
+ */
10
+ export interface ScrollTimelineConfig {
11
+ /** Name of the timeline */
12
+ name: string;
13
+ /** What drives the timeline */
14
+ source: 'scroll' | 'view';
15
+ /** The scrollable element (default: nearest scrollable ancestor) */
16
+ scroller?: 'nearest' | 'root' | 'self' | string;
17
+ /** Scroll axis */
18
+ axis?: 'block' | 'inline' | 'x' | 'y';
19
+ /** For view timelines: when does the element enter/exit */
20
+ inset?: string | {
21
+ start: string;
22
+ end: string;
23
+ };
24
+ /** Timeline range (for view timelines) */
25
+ range?: 'cover' | 'contain' | 'entry' | 'exit' | 'entry-crossing' | 'exit-crossing' | string;
26
+ }
27
+ export interface KeyframeStep {
28
+ /** Percentage or keyword (e.g., '0%', 'from', 'to') */
29
+ offset: string;
30
+ /** CSS properties at this keyframe */
31
+ properties: Record<string, string | number>;
32
+ /** Easing for this segment */
33
+ easing?: string;
34
+ }
35
+ export interface ScrollAnimation {
36
+ /** Selector to animate */
37
+ selector: string;
38
+ /** Timeline configuration */
39
+ timeline: ScrollTimelineConfig;
40
+ /** Keyframes */
41
+ keyframes: KeyframeStep[];
42
+ /** Animation duration (maps to timeline range) */
43
+ duration?: string;
44
+ /** Fill mode */
45
+ fill?: 'none' | 'forwards' | 'backwards' | 'both';
46
+ /** Iteration count */
47
+ iterations?: number | 'infinite';
48
+ /** Delay before starting */
49
+ delay?: string;
50
+ }
51
+ export interface ScrollTimelineResult {
52
+ /** Native CSS for scroll-driven animation */
53
+ css: string;
54
+ /** The @keyframes name generated */
55
+ animationName: string;
56
+ /** The timeline name generated */
57
+ timelineName: string;
58
+ /** Fallback CSS for browsers without scroll-timeline */
59
+ fallback: string;
60
+ }
61
+ export declare const SCROLL_PRESETS: Record<string, ScrollAnimation>;
62
+ /**
63
+ * Compile a scroll animation into CSS.
64
+ *
65
+ * Output includes:
66
+ * - @keyframes definition
67
+ * - animation-timeline property
68
+ * - animation-range (for view timelines)
69
+ * - @supports fallback for older browsers
70
+ */
71
+ export declare function compileScrollAnimation(animation: ScrollAnimation): ScrollTimelineResult;
72
+ /**
73
+ * Compile multiple scroll animations for a page.
74
+ */
75
+ export declare function compileScrollAnimations(animations: ScrollAnimation[]): string;
76
+ /**
77
+ * Create a scroll animation from a preset.
78
+ */
79
+ export declare function createScrollAnimation(preset: keyof typeof SCROLL_PRESETS, selector: string, overrides?: Partial<ScrollAnimation>): ScrollAnimation;
80
+ /**
81
+ * Get available scroll animation presets.
82
+ */
83
+ export declare function getScrollPresets(): string[];
84
+ export declare const scrollTimeline: {
85
+ compile: typeof compileScrollAnimation;
86
+ compileAll: typeof compileScrollAnimations;
87
+ create: typeof createScrollAnimation;
88
+ presets: Record<string, ScrollAnimation>;
89
+ getPresets: typeof getScrollPresets;
90
+ };
91
+ export default scrollTimeline;
@@ -0,0 +1,30 @@
1
+ import type { StyleDefinition, StyleGraph, StyleGraphNode, StyleGraphEdge, GraphCompileOptions, GraphCompileResult } from '../core/types.js';
2
+ export type { StyleGraph, StyleGraphNode, StyleGraphEdge, GraphCompileOptions, GraphCompileResult };
3
+ export declare class StyleGraphCompiler {
4
+ private options;
5
+ constructor(options?: GraphCompileOptions);
6
+ /**
7
+ * Compile a set of style definitions through the graph compiler.
8
+ */
9
+ compile(styles: Record<string, StyleDefinition>): GraphCompileResult;
10
+ /**
11
+ * Analyze a style graph without generating CSS.
12
+ */
13
+ analyze(styles: Record<string, StyleDefinition>): StyleGraph;
14
+ /**
15
+ * Get optimization statistics for a graph.
16
+ */
17
+ getStats(graph: StyleGraph): {
18
+ totalNodes: number;
19
+ deadNodes: number;
20
+ mergedGroups: number;
21
+ averageSpecificity: number;
22
+ deepestDependencyChain: number;
23
+ };
24
+ /**
25
+ * Update options.
26
+ */
27
+ configure(options: Partial<GraphCompileOptions>): void;
28
+ }
29
+ export declare function compileGraph(styles: Record<string, StyleDefinition>, options?: GraphCompileOptions): GraphCompileResult;
30
+ export default StyleGraphCompiler;
@@ -1,5 +1,6 @@
1
1
  import type { ChainCSSConfig, CompileResult, StyleDefinition } from './types.js';
2
2
  import { AtomicOptimizer } from '../compiler/atomic-optimizer.js';
3
+ import type { GraphCompileOptions } from '../compiler/style-graph.js';
3
4
  export declare class ChainCSSCompiler {
4
5
  private config;
5
6
  private prefixer;
@@ -18,6 +19,17 @@ export declare class ChainCSSCompiler {
18
19
  private compileQueue;
19
20
  private lruList;
20
21
  constructor(config: ChainCSSConfig);
22
+ /**
23
+ * Compile using the style graph compiler for advanced optimizations.
24
+ *
25
+ * @example
26
+ * const result = compiler.compileWithGraph(styles, {
27
+ * eliminateDead: true,
28
+ * knownSelectors: ['.header', '.footer'],
29
+ * mergeIdentical: true
30
+ * });
31
+ */
32
+ compileWithGraph(styles: Record<string, import('./types.js').StyleDefinition>, options?: GraphCompileOptions): import('./types.js').GraphCompileResult;
21
33
  hasStyles(): boolean;
22
34
  private processStyleObject;
23
35
  private addToCache;
@@ -199,3 +199,148 @@ export declare function isStyleDefinition(value: any): value is StyleDefinition;
199
199
  export declare function isAtRule(value: any): value is AtRule;
200
200
  export declare function isAtomicClass(value: any): value is AtomicClass;
201
201
  export declare function isCompileResult(value: any): value is CompileResult;
202
+ export type CSSUnit = 'px' | 'rem' | 'em' | '%' | 'vw' | 'vh' | 'vmin' | 'vmax' | 'ch' | 'ex' | 'cm' | 'mm' | 'in' | 'pt' | 'pc' | 'deg' | 'rad' | 'turn' | 'grad' | 's' | 'ms' | 'dpi' | 'dpcm' | 'dppx';
203
+ export interface CSSMathValue {
204
+ value: number;
205
+ unit: CSSUnit;
206
+ }
207
+ export interface MathContext {
208
+ rootFontSize?: number;
209
+ viewportWidth?: number;
210
+ viewportHeight?: number;
211
+ parentFontSize?: number;
212
+ dpi?: number;
213
+ elementWidth?: number;
214
+ elementHeight?: number;
215
+ }
216
+ export interface MathResult {
217
+ value: number;
218
+ unit: CSSUnit | 'calc' | 'mixed';
219
+ expression: string;
220
+ resolved: CSSMathValue | null;
221
+ explanations: string[];
222
+ toString(): string;
223
+ toCalc(): string;
224
+ }
225
+ export interface FluidTypeConfig {
226
+ minSize: number;
227
+ maxSize: number;
228
+ minWidth?: number;
229
+ maxWidth?: number;
230
+ unit?: 'px' | 'rem';
231
+ rootFontSize?: number;
232
+ }
233
+ export interface IntentRule {
234
+ input: string | RegExp;
235
+ output: string | ((match: RegExpMatchArray) => string);
236
+ defaults?: Record<string, string | number>;
237
+ confidence: number;
238
+ description: string;
239
+ }
240
+ export interface CorrectionResult {
241
+ original: string;
242
+ property: string;
243
+ corrected: string;
244
+ defaults: Record<string, string | number>;
245
+ confidence: number;
246
+ intent: string;
247
+ explanation: string;
248
+ }
249
+ export interface IntentContext {
250
+ property?: string;
251
+ value?: string;
252
+ selector?: string;
253
+ parentStyles?: Record<string, any>;
254
+ mediaContext?: string;
255
+ themeContext?: string;
256
+ }
257
+ export type HealMode = 'strict' | 'dev' | 'smart';
258
+ export interface HealResult {
259
+ fixed: Record<string, any>;
260
+ corrections: CorrectionResult[];
261
+ warnings: string[];
262
+ mode: HealMode;
263
+ }
264
+ export interface StyleGraphNode {
265
+ id: string;
266
+ selector: string;
267
+ properties: Record<string, string | number>;
268
+ specificity: number;
269
+ dependencies: string[];
270
+ dependents: string[];
271
+ mediaQuery?: string;
272
+ isDead: boolean;
273
+ hash: string;
274
+ sourceComponent?: string;
275
+ }
276
+ export interface StyleGraphEdge {
277
+ from: string;
278
+ to: string;
279
+ type: 'extends' | 'overrides' | 'references';
280
+ }
281
+ export interface StyleGraph {
282
+ nodes: Map<string, StyleGraphNode>;
283
+ edges: StyleGraphEdge[];
284
+ rootNodes: string[];
285
+ leafNodes: string[];
286
+ }
287
+ export interface GraphCompileOptions {
288
+ eliminateDead?: boolean;
289
+ knownSelectors?: string[];
290
+ mergeIdentical?: boolean;
291
+ mergeThreshold?: number;
292
+ sortOutput?: 'specificity' | 'source-order' | 'topological';
293
+ verbose?: boolean;
294
+ }
295
+ export interface GraphCompileResult extends CompileResult {
296
+ graph: StyleGraph;
297
+ eliminatedDead: number;
298
+ mergedRules: number;
299
+ optimizationTime: number;
300
+ preOptimizationSize: number;
301
+ postOptimizationSize: number;
302
+ }
303
+ export type DiagnosticSeverity = 'error' | 'warning' | 'info' | 'hint';
304
+ export interface StyleDiagnostic {
305
+ property: string;
306
+ value?: string;
307
+ selector?: string;
308
+ severity: DiagnosticSeverity;
309
+ message: string;
310
+ suggestion?: string;
311
+ code?: string;
312
+ source?: string;
313
+ range?: {
314
+ startLine: number;
315
+ startColumn: number;
316
+ endLine: number;
317
+ endColumn: number;
318
+ };
319
+ }
320
+ export interface StyleAnalysis {
321
+ diagnostics: StyleDiagnostic[];
322
+ conflicts: StyleDiagnostic[];
323
+ breakpoints: BreakpointConfig[];
324
+ unusedSelectors: string[];
325
+ deadStyles: string[];
326
+ duplicationWarnings: StyleDiagnostic[];
327
+ optimizationSuggestions: StyleDiagnostic[];
328
+ stats: {
329
+ totalProperties: number;
330
+ totalSelectors: number;
331
+ shorthandOpportunities: number;
332
+ animationSuggestions: number;
333
+ responsiveIssues: number;
334
+ };
335
+ }
336
+ export interface BreakpointInference {
337
+ selector: string;
338
+ property: string;
339
+ currentValue: string;
340
+ suggestedBreakpoint: string;
341
+ suggestedValue: string;
342
+ reason: string;
343
+ }
344
+ export declare function isMathResult(value: any): value is MathResult;
345
+ export declare function isCorrectionResult(value: any): value is CorrectionResult;
346
+ export declare function isGraphCompileResult(value: any): value is GraphCompileResult;
package/dist/index.d.ts CHANGED
@@ -40,6 +40,10 @@ export type { Chain } from './compiler/Chain.js';
40
40
  export type { AnimationConfig, KeyframeDefinition } from './compiler/animations.js';
41
41
  export type { BreakpointsMap, ResponsiveStyle } from './compiler/breakpoints.js';
42
42
  export declare const VERSION = "3.0.0";
43
+ export { orchestrator, contrastRatio, checkContrast, auditContrast, createContextualToken, resolveContextual, generateContextualCSS, validateTokenRelationships, } from './compiler/design-orchestrator.js';
44
+ export type { ContrastResult, ContrastReport, ContextualToken, TokenContext } from './compiler/design-orchestrator.js';
45
+ export { scrollTimeline, compileScrollAnimation, compileScrollAnimations, createScrollAnimation, getScrollPresets, SCROLL_PRESETS, } from './compiler/scroll-timeline.js';
46
+ export type { ScrollTimelineConfig, ScrollAnimation, ScrollTimelineResult, KeyframeStep } from './compiler/scroll-timeline.js';
43
47
  import { chain } from './compiler/Chain.js';
44
48
  export default chain;
45
49
  export type { Properties as CSSProperties } from 'csstype';
@@ -55,3 +59,11 @@ export type ResponsiveValue<T> = T | {
55
59
  };
56
60
  export type StyleWithTokens<T = any> = T | ((tokens: DesignTokens) => T);
57
61
  import { DesignTokens } from './compiler/tokens.js';
62
+ export { math, add, subtract, multiply, divide, fluidType, convert, toPx, scale } from './compiler/math-engine.js';
63
+ export type { CSSUnit, CSSMathValue, MathContext, MathResult, FluidTypeConfig } from './compiler/math-engine.js';
64
+ export { intent, correct, heal, validate as validateValue, getIntent } from './compiler/intent-engine.js';
65
+ export type { CorrectionResult, HealMode, HealResult, IntentContext } from './compiler/intent-engine.js';
66
+ export { StyleGraphCompiler, compileGraph } from './compiler/style-graph.js';
67
+ export type { StyleGraph, StyleGraphNode, StyleGraphEdge, GraphCompileOptions, GraphCompileResult } from './compiler/style-graph.js';
68
+ export { StyleAnalyzer, analyze as analyzeStyle } from './compiler/analyzer.js';
69
+ export type { StyleDiagnostic, StyleAnalysis, BreakpointInference, DiagnosticSeverity } from './compiler/analyzer.js';