chaincss 2.0.7 → 2.1.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.
Files changed (159) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/CODE_OF_CONDUCT.md +21 -0
  3. package/CONTRIBUTING.md +28 -0
  4. package/README.md +455 -226
  5. package/demo/demo/node_modules/caniuse-db/fulldata-json/data-2.0.json +1 -0
  6. package/demo/index.html +16 -0
  7. package/demo/package.json +20 -0
  8. package/demo/src/App.tsx +117 -0
  9. package/demo/src/chaincss-barrel.ts +9 -0
  10. package/demo/src/main.tsx +8 -0
  11. package/demo/src/styles.chain.ts +300 -0
  12. package/demo/vite.config.ts +46 -0
  13. package/dist/cli/commands/build.d.ts +0 -1
  14. package/dist/cli/commands/cache.d.ts +1 -0
  15. package/dist/cli/commands/init.d.ts +6 -3
  16. package/dist/cli/commands/timeline.d.ts +0 -1
  17. package/dist/cli/commands/watch.d.ts +0 -1
  18. package/dist/cli/index.d.ts +0 -1
  19. package/dist/cli/index.js +3213 -5296
  20. package/dist/cli/types.d.ts +51 -20
  21. package/dist/cli/utils/config-loader.d.ts +0 -1
  22. package/dist/cli/utils/file-utils.d.ts +27 -3
  23. package/dist/cli/utils/logger.d.ts +0 -1
  24. package/dist/compiler/Chain.d.ts +215 -0
  25. package/dist/compiler/animations.d.ts +76 -0
  26. package/dist/compiler/atomic-optimizer.d.ts +47 -12
  27. package/dist/compiler/breakpoints.d.ts +46 -0
  28. package/dist/compiler/btt.d.ts +36 -60
  29. package/dist/compiler/cache-manager.d.ts +58 -4
  30. package/dist/compiler/commonProps.d.ts +0 -1
  31. package/dist/compiler/content-addressable-cache.d.ts +78 -0
  32. package/dist/compiler/helpers.d.ts +54 -0
  33. package/dist/compiler/index.d.ts +16 -9
  34. package/dist/compiler/index.js +4450 -4316
  35. package/dist/compiler/prefixer.d.ts +17 -1
  36. package/dist/compiler/shorthands.d.ts +28 -0
  37. package/dist/compiler/suggestions.d.ts +43 -0
  38. package/dist/compiler/theme-contract.d.ts +16 -27
  39. package/dist/compiler/token-resolver.d.ts +69 -0
  40. package/dist/compiler/tokens.d.ts +33 -8
  41. package/dist/core/auto-detector.d.ts +34 -0
  42. package/dist/core/common-utils.d.ts +97 -0
  43. package/dist/core/compiler.d.ts +63 -23
  44. package/dist/core/constants.d.ts +137 -36
  45. package/dist/core/smart-chain.d.ts +3 -0
  46. package/dist/core/types.d.ts +122 -15
  47. package/dist/core/utils.d.ts +134 -17
  48. package/dist/index.d.ts +52 -8
  49. package/dist/index.js +7090 -5578
  50. package/dist/plugins/vite.d.ts +7 -5
  51. package/dist/plugins/vite.js +2964 -25641
  52. package/dist/plugins/webpack.d.ts +24 -1
  53. package/dist/plugins/webpack.js +209 -72
  54. package/dist/runtime/Chain.d.ts +32 -0
  55. package/dist/runtime/auto-hooks.d.ts +11 -0
  56. package/dist/runtime/hmr.d.ts +22 -2
  57. package/dist/runtime/index.d.ts +3 -2
  58. package/dist/runtime/index.js +3648 -301
  59. package/dist/runtime/injector.d.ts +39 -72
  60. package/dist/runtime/react.d.ts +17 -12
  61. package/dist/runtime/svelte.d.ts +15 -0
  62. package/dist/runtime/types.d.ts +126 -4
  63. package/dist/runtime/utils.d.ts +0 -1
  64. package/dist/runtime/vue.d.ts +34 -14
  65. package/package.json +59 -66
  66. package/src/cli/commands/build.ts +133 -0
  67. package/src/cli/commands/cache.ts +371 -0
  68. package/src/cli/commands/init.ts +230 -0
  69. package/src/cli/commands/timeline.ts +435 -0
  70. package/src/cli/commands/watch.ts +211 -0
  71. package/src/cli/index.ts +226 -0
  72. package/src/cli/types.ts +100 -0
  73. package/src/cli/utils/config-loader.ts +174 -0
  74. package/src/cli/utils/file-utils.ts +139 -0
  75. package/src/cli/utils/logger.ts +74 -0
  76. package/src/compiler/Chain.ts +831 -0
  77. package/src/compiler/animations.ts +517 -0
  78. package/src/compiler/atomic-optimizer.ts +786 -0
  79. package/src/compiler/breakpoints.ts +347 -0
  80. package/src/compiler/btt.ts +1147 -0
  81. package/src/compiler/cache-manager.ts +446 -0
  82. package/src/compiler/commonProps.ts +18 -0
  83. package/src/compiler/content-addressable-cache.ts +478 -0
  84. package/src/compiler/helpers.ts +407 -0
  85. package/src/compiler/index.ts +72 -0
  86. package/src/compiler/prefixer.ts +724 -0
  87. package/src/compiler/shorthands.ts +558 -0
  88. package/src/compiler/suggestions.ts +436 -0
  89. package/src/compiler/theme-contract.ts +197 -0
  90. package/src/compiler/token-resolver.ts +241 -0
  91. package/src/compiler/tokens.ts +612 -0
  92. package/src/core/auto-detector.ts +187 -0
  93. package/src/core/common-utils.ts +423 -0
  94. package/src/core/compiler.ts +835 -0
  95. package/src/core/constants.ts +424 -0
  96. package/src/core/index.ts +107 -0
  97. package/src/core/smart-chain.ts +163 -0
  98. package/src/core/types.ts +257 -0
  99. package/src/core/utils.ts +598 -0
  100. package/src/index.ts +208 -0
  101. package/src/plugins/vite.d.ts +316 -0
  102. package/src/plugins/vite.ts +424 -0
  103. package/src/plugins/webpack.d.ts +289 -0
  104. package/src/plugins/webpack.ts +416 -0
  105. package/src/runtime/Chain.ts +242 -0
  106. package/src/runtime/auto-hooks.tsx +127 -0
  107. package/src/runtime/auto-vue.ts +72 -0
  108. package/src/runtime/hmr.ts +212 -0
  109. package/src/runtime/index.ts +82 -0
  110. package/src/runtime/injector.ts +273 -0
  111. package/src/runtime/react.tsx +269 -0
  112. package/src/runtime/svelte.ts +15 -0
  113. package/src/runtime/types.ts +256 -0
  114. package/src/runtime/utils.ts +128 -0
  115. package/src/runtime/vite-env.d.ts +120 -0
  116. package/src/runtime/vue.ts +231 -0
  117. package/tsconfig.build.json +41 -0
  118. package/tsconfig.json +25 -0
  119. package/tsconfig.runtimes.json +18 -0
  120. package/dist/cli/cli.cjs +0 -7
  121. package/dist/cli/commands/build.d.ts.map +0 -1
  122. package/dist/cli/commands/compile.d.ts +0 -3
  123. package/dist/cli/commands/compile.d.ts.map +0 -1
  124. package/dist/cli/commands/init.d.ts.map +0 -1
  125. package/dist/cli/commands/timeline.d.ts.map +0 -1
  126. package/dist/cli/commands/watch.d.ts.map +0 -1
  127. package/dist/cli/index.d.ts.map +0 -1
  128. package/dist/cli/types.d.ts.map +0 -1
  129. package/dist/cli/utils/config-loader.d.ts.map +0 -1
  130. package/dist/cli/utils/file-utils.d.ts.map +0 -1
  131. package/dist/cli/utils/logger.d.ts.map +0 -1
  132. package/dist/compiler/atomic-optimizer.d.ts.map +0 -1
  133. package/dist/compiler/btt.d.ts.map +0 -1
  134. package/dist/compiler/cache-manager.d.ts.map +0 -1
  135. package/dist/compiler/commonProps.d.ts.map +0 -1
  136. package/dist/compiler/index.d.ts.map +0 -1
  137. package/dist/compiler/prefixer.d.ts.map +0 -1
  138. package/dist/compiler/theme-contract.d.ts.map +0 -1
  139. package/dist/compiler/tokens.d.ts.map +0 -1
  140. package/dist/compiler/types.d.ts +0 -57
  141. package/dist/compiler/types.d.ts.map +0 -1
  142. package/dist/core/compiler.d.ts.map +0 -1
  143. package/dist/core/constants.d.ts.map +0 -1
  144. package/dist/core/index.d.ts +0 -4
  145. package/dist/core/index.d.ts.map +0 -1
  146. package/dist/core/types.d.ts.map +0 -1
  147. package/dist/core/utils.d.ts.map +0 -1
  148. package/dist/index.d.ts.map +0 -1
  149. package/dist/plugins/vite.d.ts.map +0 -1
  150. package/dist/plugins/webpack.d.ts.map +0 -1
  151. package/dist/runtime/hmr.d.ts.map +0 -1
  152. package/dist/runtime/index.d.ts.map +0 -1
  153. package/dist/runtime/injector.d.ts.map +0 -1
  154. package/dist/runtime/react.d.ts.map +0 -1
  155. package/dist/runtime/react.js +0 -324
  156. package/dist/runtime/types.d.ts.map +0 -1
  157. package/dist/runtime/utils.d.ts.map +0 -1
  158. package/dist/runtime/vue.d.ts.map +0 -1
  159. package/dist/runtime/vue.js +0 -286
@@ -0,0 +1,347 @@
1
+ // src/compiler/breakpoints.ts
2
+
3
+ // Types
4
+ export interface BreakpointConfig {
5
+ name: string;
6
+ minWidth?: number;
7
+ maxWidth?: number;
8
+ query: string;
9
+ priority?: number;
10
+ }
11
+
12
+ export type BreakpointsMap = Record<string, string>;
13
+ export type BreakpointValues = Record<string, number>;
14
+
15
+ // Default responsive breakpoints
16
+ const DEFAULT_BREAKPOINTS: BreakpointsMap = {
17
+ // Mobile-first breakpoints
18
+ sm: '(min-width: 640px)',
19
+ md: '(min-width: 768px)',
20
+ lg: '(min-width: 1024px)',
21
+ xl: '(min-width: 1280px)',
22
+ '2xl': '(min-width: 1536px)',
23
+
24
+ // Desktop-first breakpoints (alternative naming)
25
+ mobile: '(max-width: 767px)',
26
+ tablet: '(min-width: 768px) and (max-width: 1023px)',
27
+ desktop: '(min-width: 1024px)',
28
+
29
+ // Specific device breakpoints
30
+ 'mobile-sm': '(max-width: 375px)',
31
+ 'mobile-md': '(min-width: 376px) and (max-width: 768px)',
32
+ 'tablet-sm': '(min-width: 769px) and (max-width: 834px)',
33
+ 'tablet-lg': '(min-width: 835px) and (max-width: 1024px)',
34
+ 'desktop-sm': '(min-width: 1025px) and (max-width: 1280px)',
35
+ 'desktop-md': '(min-width: 1281px) and (max-width: 1440px)',
36
+ 'desktop-lg': '(min-width: 1441px)',
37
+
38
+ // Orientation breakpoints
39
+ portrait: '(orientation: portrait)',
40
+ landscape: '(orientation: landscape)',
41
+
42
+ // Feature breakpoints
43
+ dark: '(prefers-color-scheme: dark)',
44
+ light: '(prefers-color-scheme: light)',
45
+ reducedMotion: '(prefers-reduced-motion: reduce)',
46
+ highContrast: '(prefers-contrast: high)',
47
+
48
+ // Print
49
+ print: 'print',
50
+
51
+ // Hover capabilities
52
+ hover: '(hover: hover)',
53
+ 'no-hover': '(hover: none)',
54
+
55
+ // Pointer capabilities
56
+ fine: '(pointer: fine)',
57
+ coarse: '(pointer: coarse)',
58
+ };
59
+
60
+ // Numerical values for breakpoints (for programmatic use)
61
+ export const BREAKPOINT_VALUES: Record<string, number> = {
62
+ sm: 640,
63
+ md: 768,
64
+ lg: 1024,
65
+ xl: 1280,
66
+ '2xl': 1536,
67
+ mobile: 767,
68
+ tablet: 1023,
69
+ desktop: 1024,
70
+ };
71
+
72
+ // Global breakpoints configuration
73
+ export let currentBreakpoints: BreakpointsMap = { ...DEFAULT_BREAKPOINTS };
74
+
75
+ // Function to set breakpoints from config
76
+ export function setBreakpoints(breakpoints: Partial<BreakpointsMap>): void {
77
+ currentBreakpoints = { ...DEFAULT_BREAKPOINTS, ...breakpoints } as BreakpointsMap;
78
+ }
79
+
80
+ // Get a specific breakpoint query
81
+ export function getBreakpoint(name: string): string | undefined {
82
+ return currentBreakpoints[name];
83
+ }
84
+
85
+ // Get all breakpoints
86
+ export function getAllBreakpoints(): BreakpointsMap {
87
+ return { ...currentBreakpoints };
88
+ }
89
+
90
+ // Reset to default breakpoints
91
+ export function resetBreakpoints(): void {
92
+ currentBreakpoints = { ...DEFAULT_BREAKPOINTS };
93
+ }
94
+
95
+ // Add a custom breakpoint
96
+ export function addBreakpoint(name: string, query: string): void {
97
+ currentBreakpoints[name] = query;
98
+ }
99
+
100
+ // Remove a breakpoint
101
+ export function removeBreakpoint(name: string): boolean {
102
+ if (name in currentBreakpoints) {
103
+ delete currentBreakpoints[name];
104
+ return true;
105
+ }
106
+ return false;
107
+ }
108
+
109
+ // Generate media query from min/max values
110
+ export function createMediaQuery(
111
+ min?: number | string,
112
+ max?: number | string,
113
+ unit: 'px' | 'rem' | 'em' = 'px'
114
+ ): string {
115
+ const conditions: string[] = [];
116
+
117
+ if (min !== undefined) {
118
+ const minValue = typeof min === 'number' ? `${min}${unit}` : min;
119
+ conditions.push(`(min-width: ${minValue})`);
120
+ }
121
+
122
+ if (max !== undefined) {
123
+ const maxValue = typeof max === 'number' ? `${max}${unit}` : max;
124
+ conditions.push(`(max-width: ${maxValue})`);
125
+ }
126
+
127
+ if (conditions.length === 0) {
128
+ return '';
129
+ }
130
+
131
+ return conditions.join(' and ');
132
+ }
133
+
134
+ // Get breakpoint numeric value
135
+ export function getBreakpointValue(name: string): number | undefined {
136
+ return BREAKPOINT_VALUES[name];
137
+ }
138
+
139
+ // Get breakpoint range
140
+ export function getBreakpointRange(name: string): { min: number; max: number } | null {
141
+ const query = currentBreakpoints[name];
142
+ if (!query) return null;
143
+
144
+ const minMatch = query.match(/min-width:\s*(\d+)px/);
145
+ const maxMatch = query.match(/max-width:\s*(\d+)px/);
146
+
147
+ return {
148
+ min: minMatch ? parseInt(minMatch[1]) : 0,
149
+ max: maxMatch ? parseInt(maxMatch[1]) : Infinity,
150
+ };
151
+ }
152
+
153
+ // Generate all breakpoint media queries for use in CSS
154
+ export function generateBreakpointCSS(selector: string, styles: Record<string, any>): string {
155
+ let css = '';
156
+
157
+ for (const [name, query] of Object.entries(currentBreakpoints)) {
158
+ css += `@media ${query} {\n`;
159
+ css += ` ${selector} {\n`;
160
+
161
+ for (const [prop, value] of Object.entries(styles)) {
162
+ const kebabProp = prop.replace(/([A-Z])/g, '-$1').toLowerCase();
163
+ css += ` ${kebabProp}: ${value};\n`;
164
+ }
165
+
166
+ css += ` }\n}\n`;
167
+ }
168
+
169
+ return css;
170
+ }
171
+
172
+ // Sort breakpoints by min-width (ascending)
173
+ export function getSortedBreakpoints(): Array<{ name: string; query: string; minWidth: number }> {
174
+ const breakpointsWithWidth: Array<{ name: string; query: string; minWidth: number }> = [];
175
+
176
+ for (const [name, query] of Object.entries(currentBreakpoints)) {
177
+ const minMatch = query.match(/min-width:\s*(\d+)px/);
178
+ if (minMatch) {
179
+ breakpointsWithWidth.push({
180
+ name,
181
+ query,
182
+ minWidth: parseInt(minMatch[1]),
183
+ });
184
+ }
185
+ }
186
+
187
+ return breakpointsWithWidth.sort((a, b) => a.minWidth - b.minWidth);
188
+ }
189
+
190
+ // Get breakpoint for a specific width
191
+ export function getBreakpointForWidth(width: number): string | null {
192
+ const breakpoints = getSortedBreakpoints();
193
+
194
+ for (let i = breakpoints.length - 1; i >= 0; i--) {
195
+ if (width >= breakpoints[i].minWidth) {
196
+ return breakpoints[i].name;
197
+ }
198
+ }
199
+
200
+ return null;
201
+ }
202
+
203
+ // Check if a breakpoint exists
204
+ export function hasBreakpoint(name: string): boolean {
205
+ return name in currentBreakpoints;
206
+ }
207
+
208
+ // Get all breakpoint names
209
+ export function getBreakpointNames(): string[] {
210
+ return Object.keys(currentBreakpoints);
211
+ }
212
+
213
+ // Create responsive style object for a component
214
+ export interface ResponsiveStyle<T = any> {
215
+ base?: T;
216
+ sm?: T;
217
+ md?: T;
218
+ lg?: T;
219
+ xl?: T;
220
+ '2xl'?: T;
221
+ [key: string]: T | undefined;
222
+ }
223
+
224
+ // Generate responsive CSS from a responsive style object
225
+ export function generateResponsiveCSS(
226
+ selector: string,
227
+ styles: ResponsiveStyle<Record<string, any>>
228
+ ): string {
229
+ let css = '';
230
+
231
+ // Base styles (no media query)
232
+ if (styles.base) {
233
+ css += `${selector} {\n`;
234
+ for (const [prop, value] of Object.entries(styles.base)) {
235
+ const kebabProp = prop.replace(/([A-Z])/g, '-$1').toLowerCase();
236
+ css += ` ${kebabProp}: ${value};\n`;
237
+ }
238
+ css += `}\n`;
239
+ }
240
+
241
+ // Breakpoint-specific styles
242
+ for (const [breakpoint, breakpointStyles] of Object.entries(styles)) {
243
+ if (breakpoint === 'base' || !breakpointStyles) continue;
244
+
245
+ const query = currentBreakpoints[breakpoint];
246
+ if (query) {
247
+ css += `@media ${query} {\n`;
248
+ css += ` ${selector} {\n`;
249
+
250
+ for (const [prop, value] of Object.entries(breakpointStyles)) {
251
+ const kebabProp = prop.replace(/([A-Z])/g, '-$1').toLowerCase();
252
+ css += ` ${kebabProp}: ${value};\n`;
253
+ }
254
+
255
+ css += ` }\n}\n`;
256
+ }
257
+ }
258
+
259
+ return css;
260
+ }
261
+
262
+ // Helper to create a responsive utility function
263
+ export function responsive<T>(
264
+ value: T | ResponsiveStyle<T>,
265
+ defaultBreakpoint: keyof ResponsiveStyle = 'base'
266
+ ): ResponsiveStyle<T> {
267
+ if (typeof value === 'object' && !Array.isArray(value)) {
268
+ // Check if it's already a responsive object
269
+ const keys = Object.keys(value as object);
270
+ if (keys.some(k => k in currentBreakpoints || k === 'base')) {
271
+ return value as ResponsiveStyle<T>;
272
+ }
273
+ }
274
+
275
+ // Return as base value
276
+ return { [defaultBreakpoint]: value as T };
277
+ }
278
+
279
+ // Utility to merge responsive styles
280
+ export function mergeResponsiveStyles(
281
+ ...styles: ResponsiveStyle<any>[]
282
+ ): ResponsiveStyle<any> {
283
+ const merged: ResponsiveStyle<any> = {};
284
+
285
+ for (const style of styles) {
286
+ for (const [breakpoint, breakpointStyles] of Object.entries(style)) {
287
+ if (breakpointStyles) {
288
+ if (merged[breakpoint]) {
289
+ merged[breakpoint] = { ...merged[breakpoint], ...breakpointStyles };
290
+ } else {
291
+ merged[breakpoint] = { ...breakpointStyles };
292
+ }
293
+ }
294
+ }
295
+ }
296
+
297
+ return merged;
298
+ }
299
+
300
+ // Get breakpoint query with custom unit
301
+ export function getBreakpointQuery(
302
+ name: string,
303
+ unit: 'px' | 'rem' | 'em' = 'px'
304
+ ): string | undefined {
305
+ const query = currentBreakpoints[name];
306
+ if (!query) return undefined;
307
+
308
+ // Convert px to other units if needed
309
+ if (unit !== 'px') {
310
+ const pxMatch = query.match(/(\d+)px/g);
311
+ if (pxMatch) {
312
+ let convertedQuery = query;
313
+ for (const pxValue of pxMatch) {
314
+ const num = parseInt(pxValue);
315
+ let converted: string;
316
+
317
+ switch (unit) {
318
+ case 'rem':
319
+ converted = `${num / 16}rem`;
320
+ break;
321
+ case 'em':
322
+ converted = `${num / 16}em`;
323
+ break;
324
+ default:
325
+ converted = pxValue;
326
+ }
327
+
328
+ convertedQuery = convertedQuery.replace(pxValue, converted);
329
+ }
330
+ return convertedQuery;
331
+ }
332
+ }
333
+
334
+ return query;
335
+ }
336
+
337
+ // Debug: Log all current breakpoints
338
+ export function logBreakpoints(): void {
339
+ console.log('\nšŸ“± Current Breakpoints:');
340
+ console.log('═'.repeat(50));
341
+
342
+ for (const [name, query] of Object.entries(currentBreakpoints)) {
343
+ console.log(` ${name.padEnd(12)} → ${query}`);
344
+ }
345
+
346
+ console.log('═'.repeat(50) + '\n');
347
+ }