@ogxjs/core 0.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 (82) hide show
  1. package/README.md +102 -0
  2. package/dist/builder.d.ts +75 -0
  3. package/dist/builder.d.ts.map +1 -0
  4. package/dist/builder.js +243 -0
  5. package/dist/cache.d.ts +32 -0
  6. package/dist/cache.d.ts.map +1 -0
  7. package/dist/cache.js +71 -0
  8. package/dist/css.d.ts +83 -0
  9. package/dist/css.d.ts.map +1 -0
  10. package/dist/css.js +1 -0
  11. package/dist/font-registry.d.ts +34 -0
  12. package/dist/font-registry.d.ts.map +1 -0
  13. package/dist/font-registry.js +59 -0
  14. package/dist/fonts/inter/inter-300.ttf +0 -0
  15. package/dist/fonts/inter/inter-400.ttf +0 -0
  16. package/dist/fonts/inter/inter-500.ttf +0 -0
  17. package/dist/fonts/inter/inter-600.ttf +0 -0
  18. package/dist/fonts/inter/inter-700.ttf +0 -0
  19. package/dist/fonts.d.ts +29 -0
  20. package/dist/fonts.d.ts.map +1 -0
  21. package/dist/fonts.js +90 -0
  22. package/dist/index.d.ts +18 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +19 -0
  25. package/dist/ogx.d.ts +16 -0
  26. package/dist/ogx.d.ts.map +1 -0
  27. package/dist/ogx.js +104 -0
  28. package/dist/presets/blog.d.ts +31 -0
  29. package/dist/presets/blog.d.ts.map +1 -0
  30. package/dist/presets/blog.js +98 -0
  31. package/dist/presets/docs.d.ts +23 -0
  32. package/dist/presets/docs.d.ts.map +1 -0
  33. package/dist/presets/docs.js +87 -0
  34. package/dist/presets/index.d.ts +20 -0
  35. package/dist/presets/index.d.ts.map +1 -0
  36. package/dist/presets/index.js +11 -0
  37. package/dist/presets/minimal.d.ts +20 -0
  38. package/dist/presets/minimal.d.ts.map +1 -0
  39. package/dist/presets/minimal.js +53 -0
  40. package/dist/presets/social.d.ts +29 -0
  41. package/dist/presets/social.d.ts.map +1 -0
  42. package/dist/presets/social.js +66 -0
  43. package/dist/render-png.d.ts +7 -0
  44. package/dist/render-png.d.ts.map +1 -0
  45. package/dist/render-png.js +19 -0
  46. package/dist/render-svg.d.ts +7 -0
  47. package/dist/render-svg.d.ts.map +1 -0
  48. package/dist/render-svg.js +123 -0
  49. package/dist/render.d.ts +10 -0
  50. package/dist/render.d.ts.map +1 -0
  51. package/dist/render.js +180 -0
  52. package/dist/tailwind/colors.d.ts +6 -0
  53. package/dist/tailwind/colors.d.ts.map +1 -0
  54. package/dist/tailwind/colors.js +281 -0
  55. package/dist/tailwind/index.d.ts +2 -0
  56. package/dist/tailwind/index.d.ts.map +1 -0
  57. package/dist/tailwind/index.js +1 -0
  58. package/dist/tailwind/parser.d.ts +15 -0
  59. package/dist/tailwind/parser.d.ts.map +1 -0
  60. package/dist/tailwind/parser.js +1037 -0
  61. package/dist/tailwind/scales.d.ts +26 -0
  62. package/dist/tailwind/scales.d.ts.map +1 -0
  63. package/dist/tailwind/scales.js +126 -0
  64. package/dist/tailwind/test-parser.d.ts +2 -0
  65. package/dist/tailwind/test-parser.d.ts.map +1 -0
  66. package/dist/tailwind/test-parser.js +10 -0
  67. package/dist/targets.d.ts +67 -0
  68. package/dist/targets.d.ts.map +1 -0
  69. package/dist/targets.js +25 -0
  70. package/dist/types.d.ts +173 -0
  71. package/dist/types.d.ts.map +1 -0
  72. package/dist/types.js +10 -0
  73. package/dist/utils/assets.d.ts +11 -0
  74. package/dist/utils/assets.d.ts.map +1 -0
  75. package/dist/utils/assets.js +35 -0
  76. package/dist/utils/color.d.ts +14 -0
  77. package/dist/utils/color.d.ts.map +1 -0
  78. package/dist/utils/color.js +68 -0
  79. package/dist/utils/text.d.ts +14 -0
  80. package/dist/utils/text.d.ts.map +1 -0
  81. package/dist/utils/text.js +50 -0
  82. package/package.json +71 -0
@@ -0,0 +1,1037 @@
1
+ import { normalizeColor } from "../utils/color";
2
+ import { colors } from "./colors";
3
+ import { borderRadius, boxShadow, fontSize, fontWeight, opacity, spacing, } from "./scales";
4
+ const parserCache = new Map();
5
+ /**
6
+ * Main Tailwind parser function
7
+ */
8
+ export function parseTailwind(tw, theme, colorScheme) {
9
+ const style = { display: "flex" };
10
+ const classes = (Array.isArray(tw) ? tw : [tw])
11
+ .flatMap((t) => t.split(/\s+/))
12
+ .filter(Boolean);
13
+ // Performance: Memoization Cache
14
+ const cacheKey = `${classes.join(" ")}|${colorScheme || "light"}`;
15
+ if (parserCache.has(cacheKey)) {
16
+ return { ...parserCache.get(cacheKey) };
17
+ }
18
+ const gradient = {};
19
+ for (let cls of classes) {
20
+ if (cls.startsWith("dark:")) {
21
+ if (colorScheme !== "dark")
22
+ continue;
23
+ cls = cls.slice(5);
24
+ }
25
+ parseUtility(cls, style, gradient, theme);
26
+ }
27
+ // Apply gradient if direction is set
28
+ if (gradient.direction) {
29
+ const from = gradient.from || "transparent";
30
+ const to = gradient.to || "transparent";
31
+ if (gradient.via) {
32
+ style.backgroundImage = `linear-gradient(${gradient.direction}, ${from}, ${gradient.via}, ${to})`;
33
+ }
34
+ else {
35
+ style.backgroundImage = `linear-gradient(${gradient.direction}, ${from}, ${to})`;
36
+ }
37
+ }
38
+ // Performance: Save to cache
39
+ if (!theme) {
40
+ // Only cache if no custom theme is provided (to avoid theme-specific bugs)
41
+ parserCache.set(cacheKey, { ...style });
42
+ }
43
+ return style;
44
+ }
45
+ function parseUtility(cls, style, gradient, theme) {
46
+ // Handle arbitrary values: p-[32px], bg-[#1a1a1a]
47
+ const arbitraryMatch = cls.match(/^(.+?)-\[(.+)\]$/);
48
+ if (arbitraryMatch) {
49
+ const [, prefix, value] = arbitraryMatch;
50
+ parseArbitrary(prefix, value, style, gradient);
51
+ return;
52
+ }
53
+ // Display
54
+ if (cls === "flex") {
55
+ style.display = "flex";
56
+ return;
57
+ }
58
+ if (cls === "hidden") {
59
+ style.display = "none";
60
+ return;
61
+ }
62
+ // Flex direction
63
+ if (cls === "flex-row") {
64
+ style.flexDirection = "row";
65
+ return;
66
+ }
67
+ if (cls === "flex-col") {
68
+ style.flexDirection = "column";
69
+ return;
70
+ }
71
+ if (cls === "flex-row-reverse") {
72
+ style.flexDirection = "row-reverse";
73
+ return;
74
+ }
75
+ if (cls === "flex-col-reverse") {
76
+ style.flexDirection = "column-reverse";
77
+ return;
78
+ }
79
+ // Flex wrap
80
+ if (cls === "flex-wrap") {
81
+ style.flexWrap = "wrap";
82
+ return;
83
+ }
84
+ if (cls === "flex-nowrap") {
85
+ style.flexWrap = "nowrap";
86
+ return;
87
+ }
88
+ // Flex grow/shrink
89
+ if (cls === "flex-1") {
90
+ style.flexGrow = 1;
91
+ style.flexShrink = 1;
92
+ style.flexBasis = "0%";
93
+ return;
94
+ }
95
+ if (cls === "flex-auto") {
96
+ style.flexGrow = 1;
97
+ style.flexShrink = 1;
98
+ style.flexBasis = "auto";
99
+ return;
100
+ }
101
+ if (cls === "flex-initial") {
102
+ style.flexGrow = 0;
103
+ style.flexShrink = 1;
104
+ style.flexBasis = "auto";
105
+ return;
106
+ }
107
+ if (cls === "flex-none") {
108
+ style.flexGrow = 0;
109
+ style.flexShrink = 0;
110
+ style.flexBasis = "auto";
111
+ return;
112
+ }
113
+ if (cls === "grow") {
114
+ style.flexGrow = 1;
115
+ return;
116
+ }
117
+ if (cls === "grow-0") {
118
+ style.flexGrow = 0;
119
+ return;
120
+ }
121
+ if (cls === "shrink") {
122
+ style.flexShrink = 1;
123
+ return;
124
+ }
125
+ if (cls === "shrink-0") {
126
+ style.flexShrink = 0;
127
+ return;
128
+ }
129
+ // Align self
130
+ if (cls === "self-auto") {
131
+ style.alignSelf = "auto";
132
+ return;
133
+ }
134
+ if (cls === "self-start") {
135
+ style.alignSelf = "flex-start";
136
+ return;
137
+ }
138
+ if (cls === "self-end") {
139
+ style.alignSelf = "flex-end";
140
+ return;
141
+ }
142
+ if (cls === "self-center") {
143
+ style.alignSelf = "center";
144
+ return;
145
+ }
146
+ if (cls === "self-stretch") {
147
+ style.alignSelf = "stretch";
148
+ return;
149
+ }
150
+ if (cls === "self-baseline") {
151
+ style.alignSelf = "baseline";
152
+ return;
153
+ }
154
+ // Align items
155
+ if (cls === "items-start") {
156
+ style.alignItems = "flex-start";
157
+ return;
158
+ }
159
+ if (cls === "items-end") {
160
+ style.alignItems = "flex-end";
161
+ return;
162
+ }
163
+ if (cls === "items-center") {
164
+ style.alignItems = "center";
165
+ return;
166
+ }
167
+ if (cls === "items-baseline") {
168
+ style.alignItems = "baseline";
169
+ return;
170
+ }
171
+ if (cls === "items-stretch") {
172
+ style.alignItems = "stretch";
173
+ return;
174
+ }
175
+ // Justify content
176
+ if (cls === "justify-start") {
177
+ style.justifyContent = "flex-start";
178
+ return;
179
+ }
180
+ if (cls === "justify-end") {
181
+ style.justifyContent = "flex-end";
182
+ return;
183
+ }
184
+ if (cls === "justify-center") {
185
+ style.justifyContent = "center";
186
+ return;
187
+ }
188
+ if (cls === "justify-between") {
189
+ style.justifyContent = "space-between";
190
+ return;
191
+ }
192
+ if (cls === "justify-around") {
193
+ style.justifyContent = "space-around";
194
+ return;
195
+ }
196
+ if (cls === "justify-evenly") {
197
+ style.justifyContent = "space-evenly";
198
+ return;
199
+ }
200
+ // Position
201
+ if (cls === "relative") {
202
+ style.position = "relative";
203
+ return;
204
+ }
205
+ if (cls === "absolute") {
206
+ style.position = "absolute";
207
+ return;
208
+ }
209
+ // Inset
210
+ if (cls.startsWith("inset-")) {
211
+ const value = parseSpacingValue(cls.slice(6));
212
+ if (value !== undefined) {
213
+ style.top = value;
214
+ style.right = value;
215
+ style.bottom = value;
216
+ style.left = value;
217
+ }
218
+ return;
219
+ }
220
+ if (cls.startsWith("top-")) {
221
+ const value = parseSpacingValue(cls.slice(4));
222
+ if (value !== undefined)
223
+ style.top = value;
224
+ return;
225
+ }
226
+ if (cls.startsWith("right-")) {
227
+ const value = parseSpacingValue(cls.slice(6));
228
+ if (value !== undefined)
229
+ style.right = value;
230
+ return;
231
+ }
232
+ if (cls.startsWith("bottom-")) {
233
+ const value = parseSpacingValue(cls.slice(7));
234
+ if (value !== undefined)
235
+ style.bottom = value;
236
+ return;
237
+ }
238
+ if (cls.startsWith("left-")) {
239
+ const value = parseSpacingValue(cls.slice(5));
240
+ if (value !== undefined)
241
+ style.left = value;
242
+ return;
243
+ }
244
+ // Gap
245
+ if (cls.startsWith("gap-x-")) {
246
+ const value = parseSpacingValue(cls.slice(6));
247
+ if (value !== undefined)
248
+ style.columnGap = value;
249
+ return;
250
+ }
251
+ if (cls.startsWith("gap-y-")) {
252
+ const value = parseSpacingValue(cls.slice(6));
253
+ if (value !== undefined)
254
+ style.rowGap = value;
255
+ return;
256
+ }
257
+ if (cls.startsWith("gap-")) {
258
+ const value = parseSpacingValue(cls.slice(4));
259
+ if (value !== undefined)
260
+ style.gap = value;
261
+ return;
262
+ }
263
+ // Width
264
+ if (cls === "w-full") {
265
+ style.width = "100%";
266
+ return;
267
+ }
268
+ if (cls === "w-screen") {
269
+ style.width = "100vw";
270
+ return;
271
+ }
272
+ if (cls === "w-auto") {
273
+ style.width = "auto";
274
+ return;
275
+ }
276
+ if (cls === "w-fit") {
277
+ style.width = "auto";
278
+ return;
279
+ }
280
+ if (cls.startsWith("w-")) {
281
+ const value = parseSpacingValue(cls.slice(2));
282
+ if (value !== undefined)
283
+ style.width = value;
284
+ return;
285
+ }
286
+ // Height
287
+ if (cls === "h-full") {
288
+ style.height = "100%";
289
+ return;
290
+ }
291
+ if (cls === "h-screen") {
292
+ style.height = "100vh";
293
+ return;
294
+ }
295
+ if (cls === "h-auto") {
296
+ style.height = "auto";
297
+ return;
298
+ }
299
+ if (cls === "h-fit") {
300
+ style.height = "auto";
301
+ return;
302
+ }
303
+ if (cls.startsWith("h-")) {
304
+ const value = parseSpacingValue(cls.slice(2));
305
+ if (value !== undefined)
306
+ style.height = value;
307
+ return;
308
+ }
309
+ // Min/Max width and height
310
+ if (cls === "min-w-full") {
311
+ style.minWidth = "100%";
312
+ return;
313
+ }
314
+ if (cls === "max-w-full") {
315
+ style.maxWidth = "100%";
316
+ return;
317
+ }
318
+ if (cls.startsWith("max-w-")) {
319
+ const value = parseSpacingValue(cls.slice(6));
320
+ if (value !== undefined)
321
+ style.maxWidth = value;
322
+ return;
323
+ }
324
+ if (cls === "min-h-full") {
325
+ style.minHeight = "100%";
326
+ return;
327
+ }
328
+ if (cls === "max-h-full") {
329
+ style.maxHeight = "100%";
330
+ return;
331
+ }
332
+ // Padding (px/py MUST come before p- to avoid prefix collision)
333
+ if (cls.startsWith("px-")) {
334
+ const value = parseSpacingValue(cls.slice(3));
335
+ if (value !== undefined) {
336
+ style.paddingLeft = value;
337
+ style.paddingRight = value;
338
+ }
339
+ return;
340
+ }
341
+ if (cls.startsWith("py-")) {
342
+ const value = parseSpacingValue(cls.slice(3));
343
+ if (value !== undefined) {
344
+ style.paddingTop = value;
345
+ style.paddingBottom = value;
346
+ }
347
+ return;
348
+ }
349
+ if (cls.startsWith("p-")) {
350
+ const value = parseSpacingValue(cls.slice(2));
351
+ if (value !== undefined)
352
+ style.padding = value;
353
+ return;
354
+ }
355
+ if (cls.startsWith("pt-")) {
356
+ const value = parseSpacingValue(cls.slice(3));
357
+ if (value !== undefined)
358
+ style.paddingTop = value;
359
+ return;
360
+ }
361
+ if (cls.startsWith("pr-")) {
362
+ const value = parseSpacingValue(cls.slice(3));
363
+ if (value !== undefined)
364
+ style.paddingRight = value;
365
+ return;
366
+ }
367
+ if (cls.startsWith("pb-")) {
368
+ const value = parseSpacingValue(cls.slice(3));
369
+ if (value !== undefined)
370
+ style.paddingBottom = value;
371
+ return;
372
+ }
373
+ if (cls.startsWith("pl-")) {
374
+ const value = parseSpacingValue(cls.slice(3));
375
+ if (value !== undefined)
376
+ style.paddingLeft = value;
377
+ return;
378
+ }
379
+ // Margin
380
+ if (cls === "m-auto") {
381
+ style.margin = "auto";
382
+ return;
383
+ }
384
+ if (cls === "mx-auto") {
385
+ style.marginLeft = "auto";
386
+ style.marginRight = "auto";
387
+ return;
388
+ }
389
+ if (cls === "my-auto") {
390
+ style.marginTop = "auto";
391
+ style.marginBottom = "auto";
392
+ return;
393
+ }
394
+ if (cls.startsWith("m-")) {
395
+ const value = parseSpacingValue(cls.slice(2));
396
+ if (value !== undefined)
397
+ style.margin = value;
398
+ return;
399
+ }
400
+ if (cls.startsWith("mx-")) {
401
+ const value = parseSpacingValue(cls.slice(3));
402
+ if (value !== undefined) {
403
+ style.marginLeft = value;
404
+ style.marginRight = value;
405
+ }
406
+ return;
407
+ }
408
+ if (cls.startsWith("my-")) {
409
+ const value = parseSpacingValue(cls.slice(3));
410
+ if (value !== undefined) {
411
+ style.marginTop = value;
412
+ style.marginBottom = value;
413
+ }
414
+ return;
415
+ }
416
+ if (cls.startsWith("mt-")) {
417
+ const value = parseSpacingValue(cls.slice(3));
418
+ if (value !== undefined)
419
+ style.marginTop = value;
420
+ return;
421
+ }
422
+ if (cls.startsWith("mr-")) {
423
+ const value = parseSpacingValue(cls.slice(3));
424
+ if (value !== undefined)
425
+ style.marginRight = value;
426
+ return;
427
+ }
428
+ if (cls.startsWith("mb-")) {
429
+ const value = parseSpacingValue(cls.slice(3));
430
+ if (value !== undefined)
431
+ style.marginBottom = value;
432
+ return;
433
+ }
434
+ if (cls.startsWith("ml-")) {
435
+ const value = parseSpacingValue(cls.slice(3));
436
+ if (value !== undefined)
437
+ style.marginLeft = value;
438
+ return;
439
+ }
440
+ // Background Gradients
441
+ if (cls.startsWith("bg-gradient-to-")) {
442
+ const dir = cls.slice(15);
443
+ const directions = {
444
+ t: "to top",
445
+ tr: "to top right",
446
+ r: "to right",
447
+ br: "to bottom right",
448
+ b: "to bottom",
449
+ bl: "to bottom left",
450
+ l: "to left",
451
+ tl: "to top left",
452
+ };
453
+ if (directions[dir] && gradient) {
454
+ gradient.direction = directions[dir];
455
+ }
456
+ return;
457
+ }
458
+ if (cls.startsWith("from-") && gradient) {
459
+ const color = colors[cls.slice(5)];
460
+ if (color)
461
+ gradient.from = color;
462
+ return;
463
+ }
464
+ if (cls.startsWith("via-") && gradient) {
465
+ const color = colors[cls.slice(4)];
466
+ if (color)
467
+ gradient.via = color;
468
+ return;
469
+ }
470
+ if (cls.startsWith("to-") && gradient) {
471
+ const color = colors[cls.slice(3)];
472
+ if (color)
473
+ gradient.to = color;
474
+ return;
475
+ }
476
+ if (cls.startsWith("bg-grid") ||
477
+ cls.startsWith("bg-dots") ||
478
+ cls.startsWith("bg-lines")) {
479
+ const isGrid = cls.startsWith("bg-grid");
480
+ const isDots = cls.startsWith("bg-dots");
481
+ const type = isGrid ? "grid" : isDots ? "dots" : "lines";
482
+ const config = cls.startsWith("bg-grid-")
483
+ ? cls.slice(8)
484
+ : cls.startsWith("bg-dots-")
485
+ ? cls.slice(8)
486
+ : cls.startsWith("bg-lines-")
487
+ ? cls.slice(9)
488
+ : "";
489
+ let color = "rgba(128, 128, 128, 0.1)";
490
+ let size = 24;
491
+ if (config) {
492
+ const parts = config.split("-");
493
+ // Improved size extraction
494
+ const lastPart = parts[parts.length - 1];
495
+ const isNumeric = lastPart && /^\d+$/.test(lastPart);
496
+ if (isNumeric) {
497
+ // If it's just 'bg-grid-20'
498
+ if (parts.length === 1) {
499
+ size = parseInt(lastPart, 10);
500
+ }
501
+ // If it's 'bg-grid-zinc-800-20' or 'bg-dots-slate-500-10'
502
+ else if (parts.length >= 3) {
503
+ const secondToLast = parts[parts.length - 2];
504
+ if (secondToLast && /^\d+$/.test(secondToLast)) {
505
+ size = parseInt(lastPart, 10);
506
+ const colorName = parts.slice(0, -1).join("-");
507
+ if (colorName) {
508
+ const resolved = resolveColorValue(colorName, theme);
509
+ if (resolved)
510
+ color = resolved;
511
+ }
512
+ }
513
+ }
514
+ else if (parts.length === 2 && /^\d+$/.test(lastPart)) {
515
+ if (parts[0]?.match(/^(slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)$/)) {
516
+ const resolved = resolveColorValue(config, theme);
517
+ if (resolved)
518
+ color = resolved;
519
+ }
520
+ else {
521
+ size = parseInt(lastPart, 10);
522
+ }
523
+ }
524
+ }
525
+ else {
526
+ const resolved = resolveColorValue(config, theme);
527
+ if (resolved)
528
+ color = resolved;
529
+ }
530
+ }
531
+ style.backgroundSize = `${size}px ${size}px`;
532
+ if (type === "grid") {
533
+ style.backgroundImage = `linear-gradient(to right, ${color} 1px, transparent 1px), linear-gradient(to bottom, ${color} 1px, transparent 1px)`;
534
+ }
535
+ else if (type === "dots") {
536
+ style.backgroundImage = `radial-gradient(${color} 15%, transparent 16%)`;
537
+ }
538
+ else {
539
+ style.backgroundImage = `linear-gradient(to bottom, ${color} 1px, transparent 1px)`;
540
+ style.backgroundSize = `100% ${size}px`;
541
+ }
542
+ return;
543
+ }
544
+ // Background color
545
+ if (cls.startsWith("bg-")) {
546
+ const colorName = cls.slice(3);
547
+ if (colorName.startsWith("gradient-"))
548
+ return;
549
+ const resolved = resolveColorValue(colorName, theme);
550
+ if (resolved) {
551
+ style.backgroundColor = resolved;
552
+ }
553
+ return;
554
+ }
555
+ // Text color
556
+ if (cls.startsWith("text-")) {
557
+ const rest = cls.slice(5);
558
+ // Check if it's a font size
559
+ const size = fontSize[rest];
560
+ if (size) {
561
+ style.fontSize = `${size[0]}px`;
562
+ style.lineHeight = `${size[1]}px`;
563
+ return;
564
+ }
565
+ const resolved = resolveColorValue(rest, theme);
566
+ if (resolved) {
567
+ style.color = resolved;
568
+ }
569
+ // Text align
570
+ if (rest === "left")
571
+ style.textAlign = "left";
572
+ if (rest === "center")
573
+ style.textAlign = "center";
574
+ if (rest === "right")
575
+ style.textAlign = "right";
576
+ if (rest === "justify")
577
+ style.textAlign = "justify";
578
+ return;
579
+ }
580
+ // Font weight
581
+ if (cls.startsWith("font-")) {
582
+ const weightName = cls.slice(5);
583
+ const weight = fontWeight[weightName];
584
+ if (weight) {
585
+ style.fontWeight = weight;
586
+ }
587
+ return;
588
+ }
589
+ // Line height
590
+ if (cls.startsWith("leading-")) {
591
+ const value = cls.slice(8);
592
+ const spacingValue = spacing[value];
593
+ if (spacingValue !== undefined) {
594
+ style.lineHeight = spacingValue;
595
+ }
596
+ else if (value === "none") {
597
+ style.lineHeight = "1";
598
+ }
599
+ else if (value === "tight") {
600
+ style.lineHeight = "1.25";
601
+ }
602
+ else if (value === "snug") {
603
+ style.lineHeight = "1.375";
604
+ }
605
+ else if (value === "normal") {
606
+ style.lineHeight = "1.5";
607
+ }
608
+ else if (value === "relaxed") {
609
+ style.lineHeight = "1.625";
610
+ }
611
+ else if (value === "loose") {
612
+ style.lineHeight = "2";
613
+ }
614
+ return;
615
+ }
616
+ // Letter spacing
617
+ if (cls.startsWith("tracking-")) {
618
+ const value = cls.slice(9);
619
+ if (value === "tighter")
620
+ style.letterSpacing = "-0.05em";
621
+ else if (value === "tight")
622
+ style.letterSpacing = "-0.025em";
623
+ else if (value === "normal")
624
+ style.letterSpacing = "0";
625
+ else if (value === "wide")
626
+ style.letterSpacing = "0.025em";
627
+ else if (value === "wider")
628
+ style.letterSpacing = "0.05em";
629
+ else if (value === "widest")
630
+ style.letterSpacing = "0.1em";
631
+ return;
632
+ }
633
+ // Background Grain (Noise)
634
+ if (cls.startsWith("bg-grain")) {
635
+ const opacityValue = cls.includes("/")
636
+ ? Number.parseInt(cls.split("/")[1], 10) / 100
637
+ : 0.05;
638
+ const svg = `<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.6' numOctaves='3' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(#n)' opacity='${opacityValue}'/></svg>`;
639
+ const base64 = Buffer.from(svg).toString("base64");
640
+ const noiseUrl = `url(data:image/svg+xml;base64,${base64})`;
641
+ style.backgroundImage = style.backgroundImage
642
+ ? `${style.backgroundImage}, ${noiseUrl}`
643
+ : noiseUrl;
644
+ return;
645
+ }
646
+ // Border radius
647
+ if (cls.startsWith("rounded")) {
648
+ if (cls === "rounded") {
649
+ style.borderRadius = borderRadius[""] ?? 4;
650
+ return;
651
+ }
652
+ const suffix = cls.slice(8); // remove 'rounded-'
653
+ const radius = borderRadius[suffix];
654
+ if (radius !== undefined) {
655
+ style.borderRadius = radius;
656
+ }
657
+ return;
658
+ }
659
+ // Shadows
660
+ if (cls.startsWith("shadow")) {
661
+ if (cls === "shadow") {
662
+ style.boxShadow = boxShadow[""];
663
+ return;
664
+ }
665
+ if (cls === "shadow-premium") {
666
+ // Multi-layered soft shadow
667
+ style.boxShadow =
668
+ "0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1), 0 40px 60px -15px rgba(0, 0, 0, 0.25)";
669
+ return;
670
+ }
671
+ const suffix = cls.startsWith("shadow-") ? cls.slice(7) : cls.slice(6);
672
+ const shadow = boxShadow[suffix];
673
+ if (shadow !== undefined) {
674
+ style.boxShadow = shadow;
675
+ }
676
+ return;
677
+ }
678
+ // Border width
679
+ if (cls === "border") {
680
+ style.borderWidth = 1;
681
+ style.borderStyle = "solid";
682
+ return;
683
+ }
684
+ if (cls.startsWith("border-") && !cls.includes("-")) {
685
+ const width = parseInt(cls.slice(7), 10);
686
+ if (!Number.isNaN(width)) {
687
+ style.borderWidth = width;
688
+ style.borderStyle = "solid";
689
+ }
690
+ return;
691
+ }
692
+ // Border color
693
+ if (cls.startsWith("border-")) {
694
+ const colorName = cls.slice(7);
695
+ // Check theme colors first
696
+ if (theme?.[colorName]) {
697
+ style.borderColor = normalizeColor(theme[colorName]);
698
+ return;
699
+ }
700
+ // fallback to tailwind colors
701
+ const color = colors[colorName];
702
+ if (color) {
703
+ style.borderColor = normalizeColor(String(color));
704
+ }
705
+ return;
706
+ }
707
+ // Opacity
708
+ if (cls.startsWith("opacity-")) {
709
+ const value = cls.slice(8);
710
+ const op = opacity[value];
711
+ if (op !== undefined) {
712
+ style.opacity = op;
713
+ }
714
+ return;
715
+ }
716
+ // Overflow
717
+ if (cls === "overflow-hidden") {
718
+ style.overflow = "hidden";
719
+ return;
720
+ }
721
+ if (cls === "overflow-visible") {
722
+ style.overflow = "visible";
723
+ return;
724
+ }
725
+ // Text decoration
726
+ if (cls === "underline") {
727
+ style.textDecoration = "underline";
728
+ return;
729
+ }
730
+ if (cls === "line-through") {
731
+ style.textDecoration = "line-through";
732
+ return;
733
+ }
734
+ if (cls === "no-underline") {
735
+ style.textDecoration = "none";
736
+ return;
737
+ }
738
+ // Text transform
739
+ if (cls === "uppercase") {
740
+ style.textTransform = "uppercase";
741
+ return;
742
+ }
743
+ if (cls === "lowercase") {
744
+ style.textTransform = "lowercase";
745
+ return;
746
+ }
747
+ if (cls === "capitalize") {
748
+ style.textTransform = "capitalize";
749
+ return;
750
+ }
751
+ if (cls === "normal-case") {
752
+ style.textTransform = "none";
753
+ return;
754
+ }
755
+ // Whitespace
756
+ if (cls === "whitespace-normal") {
757
+ style.whiteSpace = "normal";
758
+ return;
759
+ }
760
+ if (cls === "whitespace-nowrap") {
761
+ style.whiteSpace = "nowrap";
762
+ return;
763
+ }
764
+ if (cls === "whitespace-pre") {
765
+ style.whiteSpace = "pre";
766
+ return;
767
+ }
768
+ if (cls === "whitespace-pre-line") {
769
+ style.whiteSpace = "pre-line";
770
+ return;
771
+ }
772
+ if (cls === "whitespace-pre-wrap") {
773
+ style.whiteSpace = "pre-wrap";
774
+ return;
775
+ }
776
+ // Truncate
777
+ if (cls === "truncate") {
778
+ style.overflow = "hidden";
779
+ style.textOverflow = "ellipsis";
780
+ style.whiteSpace = "nowrap";
781
+ return;
782
+ }
783
+ // Text overflow
784
+ if (cls === "text-ellipsis") {
785
+ style.textOverflow = "ellipsis";
786
+ return;
787
+ }
788
+ if (cls === "text-clip") {
789
+ style.textOverflow = "clip";
790
+ return;
791
+ }
792
+ // Object fit
793
+ if (cls === "object-contain") {
794
+ style.objectFit = "contain";
795
+ return;
796
+ }
797
+ if (cls === "object-cover") {
798
+ style.objectFit = "cover";
799
+ return;
800
+ }
801
+ if (cls === "object-none") {
802
+ style.objectFit = "none";
803
+ return;
804
+ }
805
+ // Shadow
806
+ if (cls === "shadow") {
807
+ style.boxShadow =
808
+ "0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)";
809
+ return;
810
+ }
811
+ if (cls === "shadow-sm") {
812
+ style.boxShadow = "0 1px 2px 0 rgb(0 0 0 / 0.05)";
813
+ return;
814
+ }
815
+ if (cls === "shadow-md") {
816
+ style.boxShadow =
817
+ "0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)";
818
+ return;
819
+ }
820
+ if (cls === "shadow-lg") {
821
+ style.boxShadow =
822
+ "0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)";
823
+ return;
824
+ }
825
+ if (cls === "shadow-xl") {
826
+ style.boxShadow =
827
+ "0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1)";
828
+ return;
829
+ }
830
+ if (cls === "shadow-2xl") {
831
+ style.boxShadow = "0 25px 50px -12px rgb(0 0 0 / 0.25)";
832
+ return;
833
+ }
834
+ if (cls === "shadow-none") {
835
+ style.boxShadow = "none";
836
+ return;
837
+ }
838
+ }
839
+ function parseSpacingValue(value) {
840
+ // Check for fraction values like 1/2, 1/3, 1/4, etc.
841
+ if (value.includes("/")) {
842
+ const [num, denom] = value.split("/");
843
+ const numerator = parseInt(num, 10);
844
+ const denominator = parseInt(denom, 10);
845
+ if (!Number.isNaN(numerator) &&
846
+ !Number.isNaN(denominator) &&
847
+ denominator !== 0) {
848
+ return `${(numerator / denominator) * 100}%`;
849
+ }
850
+ return undefined;
851
+ }
852
+ // Check spacing scale
853
+ const spacingValue = spacing[value];
854
+ if (spacingValue !== undefined) {
855
+ return spacingValue;
856
+ }
857
+ return undefined;
858
+ }
859
+ function parseArbitrary(prefix, value, style, gradient) {
860
+ const parsedValue = parseArbitraryValue(value);
861
+ switch (prefix) {
862
+ case "from":
863
+ if (gradient)
864
+ gradient.from = String(parsedValue);
865
+ break;
866
+ case "via":
867
+ if (gradient)
868
+ gradient.via = String(parsedValue);
869
+ break;
870
+ case "to":
871
+ if (gradient)
872
+ gradient.to = String(parsedValue);
873
+ break;
874
+ case "p":
875
+ style.padding = parsedValue;
876
+ break;
877
+ case "px":
878
+ style.paddingLeft = parsedValue;
879
+ style.paddingRight = parsedValue;
880
+ break;
881
+ case "py":
882
+ style.paddingTop = parsedValue;
883
+ style.paddingBottom = parsedValue;
884
+ break;
885
+ case "pt":
886
+ style.paddingTop = parsedValue;
887
+ break;
888
+ case "pr":
889
+ style.paddingRight = parsedValue;
890
+ break;
891
+ case "pb":
892
+ style.paddingBottom = parsedValue;
893
+ break;
894
+ case "pl":
895
+ style.paddingLeft = parsedValue;
896
+ break;
897
+ case "m":
898
+ style.margin = parsedValue;
899
+ break;
900
+ case "mx":
901
+ style.marginLeft = parsedValue;
902
+ style.marginRight = parsedValue;
903
+ break;
904
+ case "my":
905
+ style.marginTop = parsedValue;
906
+ style.marginBottom = parsedValue;
907
+ break;
908
+ case "mt":
909
+ style.marginTop = parsedValue;
910
+ break;
911
+ case "mr":
912
+ style.marginRight = parsedValue;
913
+ break;
914
+ case "mb":
915
+ style.marginBottom = parsedValue;
916
+ break;
917
+ case "ml":
918
+ style.marginLeft = parsedValue;
919
+ break;
920
+ case "w":
921
+ style.width = parsedValue;
922
+ break;
923
+ case "h":
924
+ style.height = parsedValue;
925
+ break;
926
+ case "min-w":
927
+ style.minWidth = parsedValue;
928
+ break;
929
+ case "min-h":
930
+ style.minHeight = parsedValue;
931
+ break;
932
+ case "max-w":
933
+ style.maxWidth = parsedValue;
934
+ break;
935
+ case "max-h":
936
+ style.maxHeight = parsedValue;
937
+ break;
938
+ case "gap":
939
+ style.gap = parsedValue;
940
+ break;
941
+ case "top":
942
+ style.top = parsedValue;
943
+ break;
944
+ case "right":
945
+ style.right = parsedValue;
946
+ break;
947
+ case "bottom":
948
+ style.bottom = parsedValue;
949
+ break;
950
+ case "left":
951
+ style.left = parsedValue;
952
+ break;
953
+ case "inset":
954
+ style.top = parsedValue;
955
+ style.right = parsedValue;
956
+ style.bottom = parsedValue;
957
+ style.left = parsedValue;
958
+ break;
959
+ case "bg":
960
+ style.backgroundColor = normalizeColor(String(parsedValue));
961
+ break;
962
+ case "text":
963
+ // Could be color or size
964
+ if (parsedValue.toString().includes("px") ||
965
+ parsedValue.toString().includes("rem")) {
966
+ style.fontSize = parsedValue;
967
+ }
968
+ else {
969
+ style.color = normalizeColor(String(parsedValue));
970
+ }
971
+ break;
972
+ case "rounded":
973
+ style.borderRadius = parsedValue;
974
+ break;
975
+ case "border":
976
+ // If it looks like a color, normalize and set borderColor
977
+ if (typeof parsedValue === "string" &&
978
+ (parsedValue.startsWith("#") ||
979
+ parsedValue.startsWith("rgb") ||
980
+ parsedValue.startsWith("hsl") ||
981
+ parsedValue.startsWith("oklch"))) {
982
+ style.borderColor = normalizeColor(parsedValue);
983
+ }
984
+ else {
985
+ style.borderWidth = parsedValue;
986
+ }
987
+ style.borderStyle = "solid";
988
+ break;
989
+ case "opacity":
990
+ style.opacity = parseFloat(String(parsedValue)) / 100;
991
+ break;
992
+ }
993
+ }
994
+ function parseArbitraryValue(value) {
995
+ // If it's a CSS value with units, return as string
996
+ if (/^\d+(\.\d+)?(px|rem|em|%|vw|vh)$/.test(value)) {
997
+ return value;
998
+ }
999
+ // If it's a pure number, parse it
1000
+ if (/^\d+(\.\d+)?$/.test(value)) {
1001
+ return parseFloat(value);
1002
+ }
1003
+ // Otherwise return as-is (colors, etc.)
1004
+ return value;
1005
+ }
1006
+ /**
1007
+ * Resolve a color value from theme or palette with opacity support
1008
+ */
1009
+ function resolveColorValue(name, theme) {
1010
+ if (!name)
1011
+ return undefined;
1012
+ const normalizedParts = name.split("/");
1013
+ const colorName = normalizedParts[0];
1014
+ const opacityStr = normalizedParts[1];
1015
+ if (!colorName)
1016
+ return undefined;
1017
+ let baseColor;
1018
+ if (theme?.[colorName]) {
1019
+ baseColor = theme[colorName];
1020
+ }
1021
+ else {
1022
+ baseColor = colors[colorName];
1023
+ }
1024
+ if (!baseColor)
1025
+ return undefined;
1026
+ baseColor = normalizeColor(baseColor);
1027
+ if (opacityStr && baseColor.startsWith("#")) {
1028
+ const alpha = parseInt(opacityStr, 10) / 100;
1029
+ const r = parseInt(baseColor.slice(1, 3), 16);
1030
+ const g = parseInt(baseColor.slice(3, 5), 16);
1031
+ const b = parseInt(baseColor.slice(5, 7), 16);
1032
+ return `rgba(${r}, ${g}, ${b}, ${alpha})`;
1033
+ }
1034
+ return baseColor;
1035
+ }
1036
+ export { colors } from "./colors";
1037
+ export { borderRadius, fontSize, fontWeight, opacity, spacing } from "./scales";