chaincss 2.0.7 → 2.1.1

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 +720 -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,558 @@
1
+ // chaincss/src/compiler/shorthands.ts
2
+
3
+ import { createChain } from './Chain.js';
4
+
5
+ /**
6
+ * 1. THE DICTIONARY (Simple 1-to-1 Swaps)
7
+ * Handled by the ChainClass for performance.
8
+ */
9
+ export const shorthandMap: Record<string, string> = {
10
+ 'm': 'margin', 'mt': 'marginTop', 'mr': 'marginRight', 'mb': 'marginBottom', 'ml': 'marginLeft',
11
+ 'p': 'padding', 'pt': 'paddingTop', 'pr': 'paddingRight', 'pb': 'paddingBottom', 'pl': 'paddingLeft',
12
+ 'z': 'zIndex', 'op': 'opacity', 'ov': 'overflow', 'ovx': 'overflowX', 'ovy': 'overflowY',
13
+ 'objFit': 'objectFit', 'objPos': 'objectPosition',
14
+ 'd': 'display', 'pos': 'position', 'w': 'width', 'h': 'height',
15
+ 'minW': 'minWidth', 'maxW': 'maxWidth', 'minH': 'minHeight', 'maxH': 'maxHeight',
16
+ 'bg': 'backgroundColor', 'bgImg': 'backgroundImage', 'bgPos': 'backgroundPosition', 'bgSize': 'backgroundSize',
17
+ 'c': 'color',
18
+ 'flexDir': 'flexDirection', 'flexWrap': 'flexWrap', 'justify': 'justifyContent',
19
+ 'items': 'alignItems', 'self': 'alignSelf', 'content': 'alignContent',
20
+ 'gap': 'gap', 'gapX': 'columnGap', 'gapY': 'rowGap',
21
+ 'grow': 'flexGrow', 'shrink': 'flexShrink', 'basis': 'flexBasis', 'order': 'order',
22
+ 'gridCols': 'gridTemplateColumns', 'gridRows': 'gridTemplateRows',
23
+ 'gridRow': 'gridRow', 'gridCol': 'gridColumn',
24
+ 'rounded': 'borderRadius', 'br': 'borderRadius', 'radius': 'borderRadius',
25
+ 'roundedTL': 'borderTopLeftRadius', 'roundedTR': 'borderTopRightRadius',
26
+ 'roundedBR': 'borderBottomRightRadius', 'roundedBL': 'borderBottomLeftRadius',
27
+ 'border': 'border', 'borderW': 'borderWidth', 'borderC': 'borderColor', 'borderS': 'borderStyle',
28
+ 'borderT': 'borderTop', 'borderR': 'borderRight', 'borderB': 'borderBottom', 'borderL': 'borderLeft',
29
+ 'fontF': 'fontFamily', 'text': 'color', 'align': 'textAlign',
30
+ 'fs': 'fontSize', 'fw': 'fontWeight', 'lh': 'lineHeight', 'ls': 'letterSpacing',
31
+ 'shadow': 'boxShadow', 'textShadow': 'textShadow',
32
+ 'transform': 'transform', 'transformOrigin': 'transformOrigin',
33
+ 'transition': 'transition', 'transitionAll': 'transition',
34
+ 'cursor': 'cursor', 'pointer': 'cursor', 'resize': 'resize',
35
+ 'filter': 'filter', 'backdropFilter': 'backdropFilter'
36
+ };
37
+
38
+ // Type for macro handler
39
+ type MacroHandler = (value: any, catcher: Record<string, any>, useTokens: boolean) => void;
40
+
41
+ /**
42
+ * 2. THE MACRO REGISTRY (Complex Logic)
43
+ */
44
+ export const macros: Record<string, MacroHandler> = {
45
+ // --- Spacing & Sizing ---
46
+ mx: (v, c) => {
47
+ const value = typeof v === 'number' ? `${v}px` : v;
48
+ c.marginLeft = value;
49
+ c.marginRight = value;
50
+ },
51
+ my: (v, c) => {
52
+ const value = typeof v === 'number' ? `${v}px` : v;
53
+ c.marginTop = value;
54
+ c.marginBottom = value;
55
+ },
56
+ px: (v, c) => {
57
+ const value = typeof v === 'number' ? `${v}px` : v;
58
+ c.paddingLeft = value;
59
+ c.paddingRight = value;
60
+ },
61
+ py: (v, c) => {
62
+ const value = typeof v === 'number' ? `${v}px` : v;
63
+ c.paddingTop = value;
64
+ c.paddingBottom = value;
65
+ },
66
+ size: (v, c) => { c.width = v; c.height = v; },
67
+ inset: (v, c) => {
68
+ if (typeof v === 'object') {
69
+ if (v.top !== undefined) c.top = v.top;
70
+ if (v.right !== undefined) c.right = v.right;
71
+ if (v.bottom !== undefined) c.bottom = v.bottom;
72
+ if (v.left !== undefined) c.left = v.left;
73
+ } else {
74
+ c.top = v; c.right = v; c.bottom = v; c.left = v;
75
+ }
76
+ },
77
+ insetX: (v, c) => { c.left = v; c.right = v; },
78
+ insetY: (v, c) => { c.top = v; c.bottom = v; },
79
+
80
+ // --- Borders ---
81
+ borderX: (v, c) => { c.borderLeft = v; c.borderRight = v; },
82
+ borderY: (v, c) => { c.borderTop = v; c.borderBottom = v; },
83
+
84
+ // --- Layouts & Display ---
85
+ flex: (v, c) => {
86
+ c.display = 'flex';
87
+ if (v && v !== true && typeof v === 'string') c.flex = v;
88
+ },
89
+ inlineFlex: (v, c) => { c.display = 'inline-flex'; },
90
+ grid: (v, c) => {
91
+ c.display = 'grid';
92
+ if (v && v !== true && typeof v === 'string') c.grid = v;
93
+ },
94
+ inlineGrid: (v, c) => { c.display = 'inline-grid'; },
95
+ cols: (v, c) => {
96
+ c.gridTemplateColumns = typeof v === 'number' ? `repeat(${v}, minmax(0, 1fr))` : v;
97
+ },
98
+ rows: (v, c) => {
99
+ c.gridTemplateRows = typeof v === 'number' ? `repeat(${v}, minmax(0, 1fr))` : v;
100
+ },
101
+ center: (v, c) => {
102
+ c.display = v === 'inline' ? 'inline-flex' : 'flex';
103
+ c.alignItems = 'center';
104
+ c.justifyContent = 'center';
105
+ },
106
+ flexCenter: (v, c) => {
107
+ c.display = 'flex';
108
+ c.alignItems = 'center';
109
+ c.justifyContent = 'center';
110
+ if (v === 'col' || v === 'column') c.flexDirection = 'column';
111
+ },
112
+ gridCenter: (v, c) => {
113
+ c.display = 'grid';
114
+ c.placeItems = 'center';
115
+ },
116
+ stack: (v, c) => {
117
+ c.display = 'flex';
118
+ if (typeof v === 'object') {
119
+ c.flexDirection = v.dir === 'row' ? 'row' : 'column';
120
+ c.gap = v.spacing;
121
+ } else if (v === 'row') {
122
+ c.flexDirection = 'row';
123
+ c.gap = '1rem';
124
+ } else {
125
+ c.flexDirection = 'column';
126
+ c.gap = typeof v === 'number' ? `${v}px` : v || '1rem';
127
+ }
128
+ },
129
+ gridTable: (v, c) => {
130
+ const min = typeof v === 'number' ? `${v}px` : v;
131
+ c.display = 'grid';
132
+ c.gridTemplateColumns = `repeat(auto-fit, minmax(${min}, 1fr))`;
133
+ },
134
+
135
+ // --- Visibility & Behavior ---
136
+ hide: (v, c) => {
137
+ c.opacity = 0;
138
+ c.visibility = 'hidden';
139
+ c.pointerEvents = 'none';
140
+ },
141
+ show: (v, c) => {
142
+ c.opacity = 1;
143
+ c.visibility = 'visible';
144
+ c.pointerEvents = 'auto';
145
+ },
146
+ unselectable: (v, c) => {
147
+ c.userSelect = 'none';
148
+ c.WebkitUserSelect = 'none';
149
+ c.MozUserSelect = 'none';
150
+ c.msUserSelect = 'none';
151
+ c.cursor = 'default';
152
+ },
153
+ scrollable: (v, c) => {
154
+ if (v === 'x') {
155
+ c.overflowX = 'auto';
156
+ c.overflowY = 'hidden';
157
+ } else if (v === 'y') {
158
+ c.overflowX = 'hidden';
159
+ c.overflowY = 'auto';
160
+ } else if (v === 'both') {
161
+ c.overflow = 'auto';
162
+ } else {
163
+ c.overflow = 'auto';
164
+ }
165
+ c.WebkitOverflowScrolling = 'touch';
166
+ },
167
+
168
+ // --- Positioning ---
169
+ absolute: (v, c) => handlePosition('absolute', v, c),
170
+ fixed: (v, c) => handlePosition('fixed', v, c),
171
+ sticky: (v, c) => handlePosition('sticky', v, c),
172
+ relative: (v, c) => handlePosition('relative', v, c),
173
+
174
+ // --- Shapes & Content ---
175
+ circle: (v, c) => {
176
+ c.width = v;
177
+ c.height = v;
178
+ c.borderRadius = '50%';
179
+ c.display = 'flex';
180
+ c.alignItems = 'center';
181
+ c.justifyContent = 'center';
182
+ },
183
+ square: (v, c) => {
184
+ c.width = v;
185
+ c.height = v;
186
+ c.display = 'flex';
187
+ c.alignItems = 'center';
188
+ c.justifyContent = 'center';
189
+ },
190
+ truncate: (v, c) => {
191
+ c.overflow = 'hidden';
192
+ c.textOverflow = 'ellipsis';
193
+ c.whiteSpace = 'nowrap';
194
+ },
195
+ aspect: (v: string, c) => {
196
+ const map: Record<string, string> = {
197
+ square: '1 / 1',
198
+ video: '16 / 9',
199
+ golden: '1.618 / 1',
200
+ portrait: '3 / 4',
201
+ landscape: '4 / 3'
202
+ };
203
+ c.aspectRatio = map[v] || v;
204
+ },
205
+
206
+ // --- Aesthetic Effects ---
207
+ glass: (v, c) => {
208
+ const blur = typeof v === 'number' ? `${v}px` : v || '10px';
209
+ c.backdropFilter = `blur(${blur})`;
210
+ c.WebkitBackdropFilter = `blur(${blur})`;
211
+ c.backgroundColor = 'rgba(255, 255, 255, 0.1)';
212
+ c.border = '1px solid rgba(255, 255, 255, 0.2)';
213
+ },
214
+ glow: (v, c) => {
215
+ let color: string;
216
+ let size: number;
217
+
218
+ if (typeof v === 'string') {
219
+ color = v;
220
+ size = 20;
221
+ } else {
222
+ color = v.color || 'rgba(255,255,255,0.5)';
223
+ size = v.size || 20;
224
+ }
225
+
226
+ c.boxShadow = `0 0 ${size/4}px ${color}, 0 0 ${size/2}px ${color}, 0 0 ${size}px ${color}`;
227
+ },
228
+ textGradient: (v, c) => {
229
+ let colors: string[];
230
+ let angle: number;
231
+
232
+ if (Array.isArray(v)) {
233
+ colors = v;
234
+ angle = 90;
235
+ } else {
236
+ colors = v.colors;
237
+ angle = v.angle || 90;
238
+ }
239
+
240
+ c.backgroundImage = `linear-gradient(${angle}deg, ${colors.join(', ')})`;
241
+ c.WebkitBackgroundClip = 'text';
242
+ c.backgroundClip = 'text';
243
+ c.WebkitTextFillColor = 'transparent';
244
+ c.color = 'transparent';
245
+ c.display = 'inline-block';
246
+ },
247
+ meshGradient: (v, c) => {
248
+ const [c1, c2, c3, c4] = Array.isArray(v) ? v : [v[0], v[1], v[2], v[3]];
249
+ c.backgroundColor = c1;
250
+ c.backgroundImage = `radial-gradient(at 0% 0%, ${c2} 0px, transparent 50%), radial-gradient(at 100% 0%, ${c3} 0px, transparent 50%), radial-gradient(at 100% 100%, ${c4} 0px, transparent 50%)`;
251
+ },
252
+ noise: (v, c) => {
253
+ const op = typeof v === 'number' ? v : 0.05;
254
+ c.backgroundImage = `url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='${op}'/%3E%3C/svg%3E")`;
255
+ },
256
+
257
+ // --- Logic & Responsive ---
258
+ skeleton: (v, c) => {
259
+ let active: boolean;
260
+ let baseColor: string;
261
+ let highlightColor: string;
262
+
263
+ if (typeof v === 'boolean') {
264
+ active = v;
265
+ baseColor = 'rgba(0,0,0,0.1)';
266
+ highlightColor = 'rgba(0,0,0,0.05)';
267
+ } else {
268
+ active = v.active;
269
+ baseColor = v.color || 'rgba(0,0,0,0.1)';
270
+ highlightColor = v.highlight || 'rgba(0,0,0,0.05)';
271
+ }
272
+
273
+ if (!active) return;
274
+
275
+ c.backgroundColor = baseColor;
276
+ c.backgroundImage = `linear-gradient(90deg, ${baseColor} 25%, ${highlightColor} 50%, ${baseColor} 75%)`;
277
+ c.backgroundSize = '200% 100%';
278
+ c.animation = 'skeleton-loading 1.5s infinite linear';
279
+
280
+ if (!c.atRules) c.atRules = [];
281
+ c.atRules.push({
282
+ type: 'keyframes',
283
+ name: 'skeleton-loading',
284
+ steps: {
285
+ '0%': { backgroundPosition: '200% 0' },
286
+ '100%': { backgroundPosition: '-200% 0' }
287
+ }
288
+ });
289
+ },
290
+ fluidText: (v, c) => {
291
+ const min = typeof v.min === 'number' ? `${v.min}px` : v.min;
292
+ const max = typeof v.max === 'number' ? `${v.max}px` : v.max;
293
+ c.fontSize = `clamp(${min}, ${v.vw || '4vw'}, ${max})`;
294
+ },
295
+ safeArea: (v, c) => {
296
+ const edges = Array.isArray(v) ? v : [v || 'all'];
297
+ const map: Record<string, string> = {
298
+ top: 'Top',
299
+ bottom: 'Bottom',
300
+ left: 'Left',
301
+ right: 'Right'
302
+ };
303
+
304
+ edges.forEach(e => {
305
+ if (e === 'all') {
306
+ Object.keys(map).forEach(k => {
307
+ c[`padding${map[k]}`] = `env(safe-area-inset-${k})`;
308
+ });
309
+ } else if (map[e]) {
310
+ c[`padding${map[e]}`] = `env(safe-area-inset-${e})`;
311
+ }
312
+ });
313
+ },
314
+
315
+ // --- Nested Rules & Interactions ---
316
+ clickScale: (v, c) => {
317
+ const s = typeof v === 'number' ? v : 0.95;
318
+ if (!c.nestedRules) c.nestedRules = [];
319
+ c.nestedRules.push({
320
+ selector: '&:active',
321
+ styles: {
322
+ transform: `scale(${s})`,
323
+ transition: 'transform 0.1s cubic-bezier(0.4, 0, 0.2, 1)'
324
+ }
325
+ });
326
+ },
327
+ onInteracting: (v, c, useTokens) => {
328
+ const res = getSubStyles(v, useTokens);
329
+ if (!c.nestedRules) c.nestedRules = [];
330
+ ['&:hover', '&:focus-visible', '&:active'].forEach(s =>
331
+ c.nestedRules.push({ selector: s, styles: res })
332
+ );
333
+ },
334
+ children: (v, c, useTokens) => {
335
+ const res = getSubStyles(v, useTokens);
336
+ if (!c.nestedRules) c.nestedRules = [];
337
+ c.nestedRules.push({ selector: '& > *', styles: res });
338
+ },
339
+ dark: (v, c, useTokens) => handleTheme(v, c, 'dark', useTokens),
340
+ light: (v, c, useTokens) => handleTheme(v, c, 'light', useTokens),
341
+
342
+ // --- Utility Macros ---
343
+ pill: (v, c) => {
344
+ c.borderRadius = '9999px';
345
+ c.padding = '8px 20px';
346
+ c.display = 'inline-flex';
347
+ c.alignItems = 'center';
348
+ c.whiteSpace = 'nowrap';
349
+ },
350
+ containerMacro: (v, c) => {
351
+ c.width = '100%';
352
+ c.maxWidth = typeof v === 'number' ? `${v}px` : v || '1200px';
353
+ // Use the mx and px macros
354
+ macros.mx('auto', c, false);
355
+ macros.px('20px', c, false);
356
+ },
357
+ fullScreen: (v, c) => {
358
+ c.position = 'fixed';
359
+ c.top = 0; c.right = 0; c.bottom = 0; c.left = 0;
360
+ c.zIndex = typeof v === 'number' ? v : 9999;
361
+ },
362
+ shimmer: (v, c) => {
363
+ c.backgroundImage = 'linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent)';
364
+ c.backgroundSize = '200% 100%';
365
+ c.animation = 'shimmer 2s infinite linear';
366
+ if (!c.atRules) c.atRules = [];
367
+ c.atRules.push({
368
+ type: 'keyframes',
369
+ name: 'shimmer',
370
+ steps: {
371
+ '0%': { backgroundPosition: '-200% 0' },
372
+ '100%': { backgroundPosition: '200% 0' }
373
+ }
374
+ });
375
+ },
376
+ bento: (v, c, useTokens) => {
377
+ // Setup the Grid Container
378
+ c.display = 'grid';
379
+
380
+ if (typeof v === 'number') {
381
+ c.gridTemplateColumns = `repeat(${v}, minmax(0, 1fr))`;
382
+ c.gap = '16px';
383
+ } else if (typeof v === 'object') {
384
+ c.gridTemplateColumns = `repeat(${v.cols || 4}, minmax(0, 1fr))`;
385
+ c.gap = typeof v.gap === 'number' ? `${v.gap}px` : v.gap || '16px';
386
+ }
387
+
388
+ // Setup the Children
389
+ if (!c.nestedRules) c.nestedRules = [];
390
+
391
+ const childStyles = typeof v?.children === 'function'
392
+ ? getSubStyles(v.children, useTokens)
393
+ : {
394
+ borderRadius: '12px',
395
+ padding: '20px',
396
+ backgroundColor: 'rgba(255,255,255,0.05)'
397
+ };
398
+
399
+ c.nestedRules.push({
400
+ selector: '& > *',
401
+ styles: childStyles
402
+ });
403
+ },
404
+ pressable: (v, c, useTokens) => {
405
+ c.cursor = 'pointer';
406
+ macros.unselectable(v, c, useTokens);
407
+ macros.clickScale(v, c, useTokens);
408
+ // Add hover effect
409
+ if (!c.nestedRules) c.nestedRules = [];
410
+ c.nestedRules.push({
411
+ selector: '&:hover',
412
+ styles: { opacity: 0.8 }
413
+ });
414
+ },
415
+ focusRing: (v, c, useTokens) => {
416
+ const ringColor = typeof v === 'string' ? v : '#3b82f6';
417
+ // Use onInteracting to handle focus styles
418
+ if (!c.nestedRules) c.nestedRules = [];
419
+ c.nestedRules.push({
420
+ selector: '&:focus-visible',
421
+ styles: {
422
+ outline: `2px solid ${ringColor}`,
423
+ outlineOffset: '2px'
424
+ }
425
+ });
426
+ },
427
+ outlineDebug: (v, c) => {
428
+ c.border = '1px solid red';
429
+ if (!c.nestedRules) c.nestedRules = [];
430
+ c.nestedRules.push({
431
+ selector: '& > *',
432
+ styles: { outline: '1px solid rgba(0,255,0,0.5)' }
433
+ });
434
+ },
435
+ parallax: (v, c) => {
436
+ c.transformStyle = 'preserve-3d';
437
+ c.perspective = '1px';
438
+ c.height = '100vh';
439
+ c.overflowX = 'hidden';
440
+ c.overflowY = 'auto';
441
+ if (!c.nestedRules) c.nestedRules = [];
442
+ const scale = typeof v === 'number' ? v : 2;
443
+ c.nestedRules.push({
444
+ selector: '& > *',
445
+ styles: { transform: `translateZ(-1px) scale(${scale})` }
446
+ });
447
+ },
448
+ lineClamp: (v, c) => {
449
+ const lines = typeof v === 'number' ? v : 3;
450
+ c.display = '-webkit-box';
451
+ c.WebkitLineClamp = lines;
452
+ c.WebkitBoxOrient = 'vertical';
453
+ c.overflow = 'hidden';
454
+ },
455
+ frostedNav: (v, c, useTokens) => {
456
+ macros.fixed({ top: 0, left: 0 }, c, useTokens);
457
+ c.width = '100%';
458
+ macros.glass(v || 15, c, useTokens);
459
+ macros.safeArea('top', c, useTokens);
460
+ c.zIndex = 1000;
461
+ }
462
+ };
463
+
464
+ /**
465
+ * HELPERS
466
+ */
467
+ function handlePosition(type: string, v: any, c: any): void {
468
+ c.position = type;
469
+ if (v && typeof v === 'object') {
470
+ if (v.top !== undefined) c.top = v.top;
471
+ if (v.right !== undefined) c.right = v.right;
472
+ if (v.bottom !== undefined) c.bottom = v.bottom;
473
+ if (v.left !== undefined) c.left = v.left;
474
+ } else if (v !== undefined && typeof v !== 'boolean') {
475
+ // If a single value is provided, apply to all sides
476
+ c.top = v;
477
+ c.right = v;
478
+ c.bottom = v;
479
+ c.left = v;
480
+ }
481
+ }
482
+
483
+ function getSubStyles(callback: any, useTokens: boolean): Record<string, any> {
484
+ const sub = createChain(useTokens);
485
+ callback(sub);
486
+ const result = sub.$el();
487
+ const { selectors, atRules, nestedRules, ...pure } = result;
488
+ return pure;
489
+ }
490
+
491
+ function handleTheme(cb: any, c: any, mode: string, useTokens: boolean): void {
492
+ if (!c.atRules) c.atRules = [];
493
+ c.atRules.push({
494
+ type: 'media',
495
+ query: `(prefers-color-scheme: ${mode})`,
496
+ styles: getSubStyles(cb, useTokens)
497
+ });
498
+ }
499
+
500
+ /**
501
+ * Main handler for shorthand processing
502
+ * Returns true if the shorthand was handled, false otherwise
503
+ */
504
+ export function handleShorthand(
505
+ prop: string,
506
+ value: any,
507
+ catcher: Record<string, any>,
508
+ useTokens: boolean = true
509
+ ): boolean {
510
+ // Check if it's a macro
511
+ if (macros[prop]) {
512
+ macros[prop](value, catcher, useTokens);
513
+ return true;
514
+ }
515
+
516
+ // Handle transform properties
517
+ if (['scale', 'rotate', 'skew'].includes(prop)) {
518
+ if (!catcher._transforms) catcher._transforms = {};
519
+ catcher._transforms[prop] = value;
520
+ return true;
521
+ }
522
+
523
+ // Handle translate X/Y
524
+ if (prop === 'x') {
525
+ if (!catcher._transforms) catcher._transforms = {};
526
+ catcher._transforms.translateX = value;
527
+ return true;
528
+ }
529
+
530
+ if (prop === 'y') {
531
+ if (!catcher._transforms) catcher._transforms = {};
532
+ catcher._transforms.translateY = value;
533
+ return true;
534
+ }
535
+
536
+ return false;
537
+ }
538
+
539
+ /**
540
+ * Utility to check if a property is a registered shorthand
541
+ */
542
+ export function isShorthand(prop: string): boolean {
543
+ return prop in shorthandMap || prop in macros;
544
+ }
545
+
546
+ /**
547
+ * Get the expanded property name for a shorthand
548
+ */
549
+ export function expandShorthand(prop: string): string | null {
550
+ return shorthandMap[prop] || null;
551
+ }
552
+
553
+ /**
554
+ * Get all available shorthands
555
+ */
556
+ export function getAvailableShorthands(): string[] {
557
+ return [...Object.keys(shorthandMap), ...Object.keys(macros)];
558
+ }