chaincss 2.1.39 → 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.
- package/dist/compiler/css-if-transpiler.d.ts +33 -0
- package/dist/compiler/design-orchestrator.d.ts +119 -0
- package/dist/compiler/intent-engine.d.ts +19 -1
- package/dist/compiler/scroll-timeline.d.ts +91 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +651 -2
- package/package.json +1 -1
- package/src/compiler/css-if-transpiler.ts +117 -0
- package/src/compiler/design-orchestrator.ts +322 -0
- package/src/compiler/intent-engine.ts +291 -1
- package/src/compiler/scroll-timeline.ts +284 -0
- package/src/index.ts +34 -0
|
@@ -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;
|
|
@@ -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,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;
|
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';
|