chai-tailwind-js 1.0.2 → 1.0.4

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.
@@ -1,34 +1,516 @@
1
- var chaiTailwind = (() => {
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
1
+ (() => {
2
+ // src/core/scanner.js
3
+ function scanDOM() {
4
+ const elements = document.querySelectorAll("[class]");
5
+ return elements;
6
+ }
7
+
8
+ // src/utils/config.js
9
+ var spacing = {};
10
+ for (let i = 0; i <= 20; i++) {
11
+ spacing[i] = `${i * 4}px`;
12
+ }
13
+ var config = {
14
+ spacing,
15
+ colors: {
16
+ red: {
17
+ 100: "#fee2e2",
18
+ 300: "#fca5a5",
19
+ 500: "#ef4444",
20
+ 700: "#b91c1c"
21
+ },
22
+ blue: {
23
+ 100: "#dbeafe",
24
+ 300: "#93c5fd",
25
+ 500: "#3b82f6",
26
+ 700: "#1d4ed8"
27
+ },
28
+ green: {
29
+ 100: "#dcfce7",
30
+ 300: "#86efac",
31
+ 500: "#22c55e",
32
+ 700: "#15803d"
33
+ },
34
+ yellow: {
35
+ 100: "#fef9c3",
36
+ 300: "#fde047",
37
+ 500: "#eab308",
38
+ 700: "#a16207"
39
+ },
40
+ purple: {
41
+ 100: "#f3e8ff",
42
+ 300: "#d8b4fe",
43
+ 500: "#a855f7",
44
+ 700: "#7e22ce"
45
+ },
46
+ pink: {
47
+ 100: "#fce7f3",
48
+ 300: "#f9a8d4",
49
+ 500: "#ec4899",
50
+ 700: "#be185d"
51
+ },
52
+ black: "black",
53
+ white: "white"
54
+ },
55
+ fontSize: {
56
+ xs: "12px",
57
+ sm: "14px",
58
+ base: "16px",
59
+ lg: "18px",
60
+ xl: "20px",
61
+ "2xl": "24px",
62
+ "3xl": "28px",
63
+ "4xl": "32px",
64
+ "5xl": "40px"
65
+ },
66
+ fontWeight: {
67
+ thin: 100,
68
+ light: 300,
69
+ normal: 400,
70
+ medium: 500,
71
+ bold: 700
72
+ },
73
+ letterSpacing: {
74
+ tight: "-0.05em",
75
+ normal: "0",
76
+ wide: "0.05em"
77
+ },
78
+ lineHeight: {
79
+ none: "1",
80
+ tight: "1.25",
81
+ normal: "1.5",
82
+ loose: "2"
83
+ },
84
+ borderRadius: {
85
+ none: "0px",
86
+ sm: "4px",
87
+ DEFAULT: "8px",
88
+ md: "10px",
89
+ lg: "12px",
90
+ xl: "16px",
91
+ full: "9999px"
92
+ },
93
+ borderWidth: {
94
+ DEFAULT: "1px",
95
+ 2: "2px",
96
+ 4: "4px"
97
+ },
98
+ shadows: {
99
+ sm: "0 1px 3px rgba(0,0,0,0.1)",
100
+ DEFAULT: "0 4px 10px rgba(0,0,0,0.1)",
101
+ md: "0 6px 20px rgba(0,0,0,0.15)",
102
+ lg: "0 10px 30px rgba(0,0,0,0.2)"
103
+ },
104
+ zIndex: {
105
+ 0: 0,
106
+ 10: 10,
107
+ 20: 20,
108
+ 50: 50,
109
+ 100: 100
110
+ },
111
+ transitionTiming: {
112
+ linear: "linear",
113
+ in: "ease-in",
114
+ out: "ease-out",
115
+ "in-out": "ease-in-out"
116
+ },
117
+ blur: {
118
+ none: "0px",
119
+ sm: "4px",
120
+ DEFAULT: "8px",
121
+ md: "12px",
122
+ lg: "16px",
123
+ xl: "24px"
124
+ },
125
+ opacity: {
126
+ 0: "0",
127
+ 5: "0.05",
128
+ 10: "0.1",
129
+ 20: "0.2",
130
+ 25: "0.25",
131
+ 30: "0.3",
132
+ 40: "0.4",
133
+ 50: "0.5",
134
+ 60: "0.6",
135
+ 70: "0.7",
136
+ 75: "0.75",
137
+ 80: "0.8",
138
+ 90: "0.9",
139
+ 95: "0.95",
140
+ 100: "1"
141
+ },
142
+ display: {
143
+ block: "block",
144
+ inline: "inline",
145
+ "inline-block": "inline-block",
146
+ flex: "flex",
147
+ grid: "grid",
148
+ hidden: "none"
149
+ },
150
+ textAlign: {
151
+ left: "left",
152
+ center: "center",
153
+ right: "right",
154
+ justify: "justify"
155
+ },
156
+ widths: {
157
+ full: "100%",
158
+ half: "50%",
159
+ third: "33.333%",
160
+ quarter: "25%",
161
+ screen: "100vw",
162
+ auto: "auto"
163
+ },
164
+ heights: {
165
+ full: "100%",
166
+ screen: "100vh",
167
+ auto: "auto"
168
+ },
169
+ cursor: {
170
+ pointer: "pointer",
171
+ default: "default",
172
+ "not-allowed": "not-allowed"
173
+ },
174
+ overflow: {
175
+ hidden: "hidden",
176
+ auto: "auto",
177
+ scroll: "scroll",
178
+ visible: "visible"
179
+ }
9
180
  };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
181
+
182
+ // src/core/parser.js
183
+ function parseClass(cls) {
184
+ let hover = null;
185
+ let utility = cls;
186
+ if (cls.includes(":")) {
187
+ const parts2 = cls.split(":");
188
+ hover = parts2[0];
189
+ utility = parts2[1];
190
+ }
191
+ if (!utility.startsWith("chai-")) return null;
192
+ utility = utility.slice(5);
193
+ if (!utility.includes("-")) return null;
194
+ const parts = utility.split("-");
195
+ const prefix = parts[0];
196
+ const value = parts.slice(1).join("-");
197
+ return {
198
+ hover,
199
+ prefix,
200
+ value
201
+ };
202
+ }
203
+
204
+ // src/runtime/interpreter.js
205
+ var handlers = {
206
+ p: (el, value) => {
207
+ const s = config.spacing[value];
208
+ if (s) el.style.padding = s;
209
+ },
210
+ m: (el, value) => {
211
+ const s = config.spacing[value];
212
+ if (s) el.style.margin = s;
213
+ },
214
+ bg: (el, value) => {
215
+ const [color, shade] = value.split("-");
216
+ const c = config.colors[color]?.[shade];
217
+ if (c) el.style.backgroundColor = c;
218
+ },
219
+ text: (el, value) => {
220
+ const parts = value.split("-");
221
+ if (parts.length === 1) {
222
+ const size = config.fontSize[value];
223
+ if (size) return el.style.fontSize = size;
224
+ const color = config.colors[value];
225
+ if (color) el.style.color = color;
226
+ } else {
227
+ const [color, shade] = parts;
228
+ const c = config.colors[color]?.[shade];
229
+ if (c) el.style.color = c;
230
+ }
231
+ },
232
+ font: (el, value) => {
233
+ const fw = config.fontWeight[value];
234
+ if (fw) el.style.fontWeight = fw;
235
+ },
236
+ tracking: (el, value) => {
237
+ const ls = config.letterSpacing[value];
238
+ if (ls) el.style.letterSpacing = ls;
239
+ },
240
+ leading: (el, value) => {
241
+ const lh = config.lineHeight[value];
242
+ if (lh) el.style.lineHeight = lh;
243
+ },
244
+ uppercase: (el) => el.style.textTransform = "uppercase",
245
+ lowercase: (el) => el.style.textTransform = "lowercase",
246
+ capitalize: (el) => el.style.textTransform = "capitalize",
247
+ rounded: (el, value) => {
248
+ const r = config.borderRadius[value || "DEFAULT"];
249
+ if (r) el.style.borderRadius = r;
250
+ },
251
+ shadow: (el, value) => {
252
+ const s = config.shadows[value || "DEFAULT"];
253
+ if (s) el.style.boxShadow = s;
254
+ },
255
+ border: (el, value) => {
256
+ if (!value) {
257
+ el.style.borderWidth = config.borderWidth.DEFAULT;
258
+ el.style.borderStyle = "solid";
259
+ return;
260
+ }
261
+ if (config.borderWidth[value]) {
262
+ el.style.borderWidth = config.borderWidth[value];
263
+ el.style.borderStyle = "solid";
264
+ return;
265
+ }
266
+ const [color, shade] = value.split("-");
267
+ const c = config.colors[color]?.[shade] || config.colors[color];
268
+ if (c) {
269
+ el.style.border = `${config.borderWidth.DEFAULT} solid ${c}`;
270
+ }
271
+ },
272
+ flex: (el, value) => {
273
+ el.style.display = "flex";
274
+ if (value === "col") el.style.flexDirection = "column";
275
+ if (value === "row") el.style.flexDirection = "row";
276
+ },
277
+ justify: (el, value) => {
278
+ const map = {
279
+ start: "flex-start",
280
+ center: "center",
281
+ end: "flex-end",
282
+ between: "space-between",
283
+ around: "space-around",
284
+ evenly: "space-evenly"
285
+ };
286
+ if (map[value]) {
287
+ el.style.display = "flex";
288
+ el.style.justifyContent = map[value];
289
+ }
290
+ },
291
+ items: (el, value) => {
292
+ const map = {
293
+ start: "flex-start",
294
+ center: "center",
295
+ end: "flex-end",
296
+ stretch: "stretch",
297
+ baseline: "baseline"
298
+ };
299
+ if (map[value]) {
300
+ el.style.display = "flex";
301
+ el.style.alignItems = map[value];
302
+ }
303
+ },
304
+ grid: (el, value) => {
305
+ el.style.display = "grid";
306
+ if (value && value.startsWith("cols-")) {
307
+ const n = value.replace("cols-", "");
308
+ el.style.gridTemplateColumns = `repeat(${n}, 1fr)`;
309
+ }
310
+ },
311
+ gap: (el, value) => {
312
+ const g = config.spacing[value];
313
+ if (g) el.style.gap = g;
314
+ },
315
+ w: (el, value) => {
316
+ const named = config.widths[value];
317
+ if (named) {
318
+ el.style.width = named;
319
+ return;
320
+ }
321
+ const s = config.spacing[value];
322
+ if (s) el.style.width = s;
323
+ },
324
+ h: (el, value) => {
325
+ const named = config.heights[value];
326
+ if (named) {
327
+ el.style.height = named;
328
+ return;
329
+ }
330
+ const s = config.spacing[value];
331
+ if (s) el.style.height = s;
332
+ },
333
+ align: (el, value) => {
334
+ const a = config.textAlign[value];
335
+ if (a) el.style.textAlign = a;
336
+ },
337
+ cursor: (el, value) => {
338
+ const c = config.cursor[value];
339
+ if (c) el.style.cursor = c;
340
+ },
341
+ overflow: (el, value) => {
342
+ const o = config.overflow[value];
343
+ if (o) el.style.overflow = o;
344
+ },
345
+ opacity: (el, value) => {
346
+ el.style.opacity = value / 100;
347
+ },
348
+ relative: (el) => el.style.position = "relative",
349
+ absolute: (el) => el.style.position = "absolute",
350
+ top: (el, value) => {
351
+ const s = config.spacing[value];
352
+ if (s) el.style.top = s;
353
+ },
354
+ left: (el, value) => {
355
+ const s = config.spacing[value];
356
+ if (s) el.style.left = s;
357
+ },
358
+ z: (el, value) => {
359
+ const z = config.zIndex[value];
360
+ if (z !== void 0) el.style.zIndex = z;
361
+ },
362
+ transition: (el) => {
363
+ el.style.transition = "all 0.2s ease";
364
+ },
365
+ duration: (el, value) => {
366
+ el.style.transitionDuration = `${value}ms`;
367
+ },
368
+ ease: (el, value) => {
369
+ const t = config.transitionTiming[value];
370
+ if (t) el.style.transitionTimingFunction = t;
371
+ },
372
+ scale: (el, value) => {
373
+ el.style.transform = `scale(${value / 100})`;
374
+ },
375
+ px: (el, value) => {
376
+ const s = config.spacing[value];
377
+ if (s) {
378
+ el.style.paddingLeft = s;
379
+ el.style.paddingRight = s;
380
+ }
381
+ },
382
+ py: (el, value) => {
383
+ const s = config.spacing[value];
384
+ if (s) {
385
+ el.style.paddingTop = s;
386
+ el.style.paddingBottom = s;
387
+ }
388
+ },
389
+ mx: (el, value) => {
390
+ const s = config.spacing[value];
391
+ if (s) {
392
+ el.style.marginLeft = s;
393
+ el.style.marginRight = s;
394
+ }
395
+ },
396
+ my: (el, value) => {
397
+ const s = config.spacing[value];
398
+ if (s) {
399
+ el.style.marginTop = s;
400
+ el.style.marginBottom = s;
401
+ }
402
+ },
403
+ mt: (el, value) => {
404
+ const s = config.spacing[value];
405
+ if (s) el.style.marginTop = s;
406
+ },
407
+ mb: (el, value) => {
408
+ const s = config.spacing[value];
409
+ if (s) el.style.marginBottom = s;
410
+ },
411
+ ml: (el, value) => {
412
+ const s = config.spacing[value];
413
+ if (s) el.style.marginLeft = s;
414
+ },
415
+ mr: (el, value) => {
416
+ const s = config.spacing[value];
417
+ if (s) el.style.marginRight = s;
418
+ },
419
+ pt: (el, value) => {
420
+ const s = config.spacing[value];
421
+ if (s) el.style.paddingTop = s;
422
+ },
423
+ pb: (el, value) => {
424
+ const s = config.spacing[value];
425
+ if (s) el.style.paddingBottom = s;
426
+ },
427
+ pl: (el, value) => {
428
+ const s = config.spacing[value];
429
+ if (s) el.style.paddingLeft = s;
430
+ },
431
+ pr: (el, value) => {
432
+ const s = config.spacing[value];
433
+ if (s) el.style.paddingRight = s;
434
+ },
435
+ "space-x": (el, value) => {
436
+ const s = config.spacing[value];
437
+ if (s) {
438
+ Array.from(el.children).forEach((child, idx) => {
439
+ if (idx > 0) child.style.marginLeft = s;
440
+ });
441
+ }
442
+ },
443
+ "space-y": (el, value) => {
444
+ const s = config.spacing[value];
445
+ if (s) {
446
+ Array.from(el.children).forEach((child, idx) => {
447
+ if (idx > 0) child.style.marginTop = s;
448
+ });
449
+ }
450
+ },
451
+ "backdrop-blur": (el, value) => {
452
+ const b = config.blur[value || "DEFAULT"];
453
+ if (b) el.style.backdropFilter = `blur(${b})`;
454
+ },
455
+ "bg-opacity": (el, value) => {
456
+ const opacity = config.opacity[value];
457
+ if (opacity !== void 0) {
458
+ const bgColor = window.getComputedStyle(el).backgroundColor;
459
+ const rgbaColor = bgColor.replace(/rgba?\(/, "rgba(").replace(/\)/, `)`);
460
+ const match = rgbaColor.match(/(rgba?\([^,]+,[^,]+,[^,]+),/);
461
+ if (match) {
462
+ el.style.backgroundColor = `${match[1]}, ${opacity})`;
463
+ }
464
+ }
465
+ },
466
+ hidden: (el) => el.style.display = "none",
467
+ block: (el) => el.style.display = "block",
468
+ inline: (el) => el.style.display = "inline",
469
+ right: (el, value) => {
470
+ const s = config.spacing[value];
471
+ if (s) el.style.right = s;
472
+ },
473
+ bottom: (el, value) => {
474
+ const s = config.spacing[value];
475
+ if (s) el.style.bottom = s;
15
476
  }
16
- return to;
17
477
  };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
478
+ function interpretClass(element, cls) {
479
+ const parsed = parseClass(cls);
480
+ if (!parsed) return;
481
+ const { hover, prefix, value } = parsed;
482
+ const handler = handlers[prefix];
483
+ if (!handler) return;
484
+ if (!hover) {
485
+ handler(element, value);
486
+ }
487
+ if (hover === "hover") {
488
+ const original = element.style.cssText;
489
+ element.addEventListener("mouseenter", () => {
490
+ handler(element, value);
491
+ });
492
+ element.addEventListener("mouseleave", () => {
493
+ element.style.cssText = original;
494
+ });
495
+ }
496
+ }
497
+
498
+ // src/core/styler.js
499
+ function applyStyles(elements) {
500
+ elements.forEach((element) => {
501
+ element.classList.forEach((cls) => {
502
+ interpretClass(element, cls);
503
+ });
504
+ });
505
+ }
19
506
 
20
507
  // src/index.js
21
- var index_exports = {};
22
- __export(index_exports, {
23
- default: () => index_default
24
- });
25
508
  function chaiTailwind() {
26
509
  const elements = scanDOM();
27
510
  applyStyles(elements);
28
511
  }
29
512
  var index_default = chaiTailwind;
30
- if (typeof window !== "undefined") {
31
- window.chaiTailwind = chaiTailwind;
32
- }
33
- return __toCommonJS(index_exports);
513
+
514
+ // src/browser.js
515
+ window.chaiTailwind = index_default;
34
516
  })();
@@ -1,12 +1,514 @@
1
+ // src/core/scanner.js
2
+ function scanDOM() {
3
+ const elements = document.querySelectorAll("[class]");
4
+ return elements;
5
+ }
6
+
7
+ // src/utils/config.js
8
+ var spacing = {};
9
+ for (let i = 0; i <= 20; i++) {
10
+ spacing[i] = `${i * 4}px`;
11
+ }
12
+ var config = {
13
+ spacing,
14
+ colors: {
15
+ red: {
16
+ 100: "#fee2e2",
17
+ 300: "#fca5a5",
18
+ 500: "#ef4444",
19
+ 700: "#b91c1c"
20
+ },
21
+ blue: {
22
+ 100: "#dbeafe",
23
+ 300: "#93c5fd",
24
+ 500: "#3b82f6",
25
+ 700: "#1d4ed8"
26
+ },
27
+ green: {
28
+ 100: "#dcfce7",
29
+ 300: "#86efac",
30
+ 500: "#22c55e",
31
+ 700: "#15803d"
32
+ },
33
+ yellow: {
34
+ 100: "#fef9c3",
35
+ 300: "#fde047",
36
+ 500: "#eab308",
37
+ 700: "#a16207"
38
+ },
39
+ purple: {
40
+ 100: "#f3e8ff",
41
+ 300: "#d8b4fe",
42
+ 500: "#a855f7",
43
+ 700: "#7e22ce"
44
+ },
45
+ pink: {
46
+ 100: "#fce7f3",
47
+ 300: "#f9a8d4",
48
+ 500: "#ec4899",
49
+ 700: "#be185d"
50
+ },
51
+ black: "black",
52
+ white: "white"
53
+ },
54
+ fontSize: {
55
+ xs: "12px",
56
+ sm: "14px",
57
+ base: "16px",
58
+ lg: "18px",
59
+ xl: "20px",
60
+ "2xl": "24px",
61
+ "3xl": "28px",
62
+ "4xl": "32px",
63
+ "5xl": "40px"
64
+ },
65
+ fontWeight: {
66
+ thin: 100,
67
+ light: 300,
68
+ normal: 400,
69
+ medium: 500,
70
+ bold: 700
71
+ },
72
+ letterSpacing: {
73
+ tight: "-0.05em",
74
+ normal: "0",
75
+ wide: "0.05em"
76
+ },
77
+ lineHeight: {
78
+ none: "1",
79
+ tight: "1.25",
80
+ normal: "1.5",
81
+ loose: "2"
82
+ },
83
+ borderRadius: {
84
+ none: "0px",
85
+ sm: "4px",
86
+ DEFAULT: "8px",
87
+ md: "10px",
88
+ lg: "12px",
89
+ xl: "16px",
90
+ full: "9999px"
91
+ },
92
+ borderWidth: {
93
+ DEFAULT: "1px",
94
+ 2: "2px",
95
+ 4: "4px"
96
+ },
97
+ shadows: {
98
+ sm: "0 1px 3px rgba(0,0,0,0.1)",
99
+ DEFAULT: "0 4px 10px rgba(0,0,0,0.1)",
100
+ md: "0 6px 20px rgba(0,0,0,0.15)",
101
+ lg: "0 10px 30px rgba(0,0,0,0.2)"
102
+ },
103
+ zIndex: {
104
+ 0: 0,
105
+ 10: 10,
106
+ 20: 20,
107
+ 50: 50,
108
+ 100: 100
109
+ },
110
+ transitionTiming: {
111
+ linear: "linear",
112
+ in: "ease-in",
113
+ out: "ease-out",
114
+ "in-out": "ease-in-out"
115
+ },
116
+ blur: {
117
+ none: "0px",
118
+ sm: "4px",
119
+ DEFAULT: "8px",
120
+ md: "12px",
121
+ lg: "16px",
122
+ xl: "24px"
123
+ },
124
+ opacity: {
125
+ 0: "0",
126
+ 5: "0.05",
127
+ 10: "0.1",
128
+ 20: "0.2",
129
+ 25: "0.25",
130
+ 30: "0.3",
131
+ 40: "0.4",
132
+ 50: "0.5",
133
+ 60: "0.6",
134
+ 70: "0.7",
135
+ 75: "0.75",
136
+ 80: "0.8",
137
+ 90: "0.9",
138
+ 95: "0.95",
139
+ 100: "1"
140
+ },
141
+ display: {
142
+ block: "block",
143
+ inline: "inline",
144
+ "inline-block": "inline-block",
145
+ flex: "flex",
146
+ grid: "grid",
147
+ hidden: "none"
148
+ },
149
+ textAlign: {
150
+ left: "left",
151
+ center: "center",
152
+ right: "right",
153
+ justify: "justify"
154
+ },
155
+ widths: {
156
+ full: "100%",
157
+ half: "50%",
158
+ third: "33.333%",
159
+ quarter: "25%",
160
+ screen: "100vw",
161
+ auto: "auto"
162
+ },
163
+ heights: {
164
+ full: "100%",
165
+ screen: "100vh",
166
+ auto: "auto"
167
+ },
168
+ cursor: {
169
+ pointer: "pointer",
170
+ default: "default",
171
+ "not-allowed": "not-allowed"
172
+ },
173
+ overflow: {
174
+ hidden: "hidden",
175
+ auto: "auto",
176
+ scroll: "scroll",
177
+ visible: "visible"
178
+ }
179
+ };
180
+
181
+ // src/core/parser.js
182
+ function parseClass(cls) {
183
+ let hover = null;
184
+ let utility = cls;
185
+ if (cls.includes(":")) {
186
+ const parts2 = cls.split(":");
187
+ hover = parts2[0];
188
+ utility = parts2[1];
189
+ }
190
+ if (!utility.startsWith("chai-")) return null;
191
+ utility = utility.slice(5);
192
+ if (!utility.includes("-")) return null;
193
+ const parts = utility.split("-");
194
+ const prefix = parts[0];
195
+ const value = parts.slice(1).join("-");
196
+ return {
197
+ hover,
198
+ prefix,
199
+ value
200
+ };
201
+ }
202
+
203
+ // src/runtime/interpreter.js
204
+ var handlers = {
205
+ p: (el, value) => {
206
+ const s = config.spacing[value];
207
+ if (s) el.style.padding = s;
208
+ },
209
+ m: (el, value) => {
210
+ const s = config.spacing[value];
211
+ if (s) el.style.margin = s;
212
+ },
213
+ bg: (el, value) => {
214
+ const [color, shade] = value.split("-");
215
+ const c = config.colors[color]?.[shade];
216
+ if (c) el.style.backgroundColor = c;
217
+ },
218
+ text: (el, value) => {
219
+ const parts = value.split("-");
220
+ if (parts.length === 1) {
221
+ const size = config.fontSize[value];
222
+ if (size) return el.style.fontSize = size;
223
+ const color = config.colors[value];
224
+ if (color) el.style.color = color;
225
+ } else {
226
+ const [color, shade] = parts;
227
+ const c = config.colors[color]?.[shade];
228
+ if (c) el.style.color = c;
229
+ }
230
+ },
231
+ font: (el, value) => {
232
+ const fw = config.fontWeight[value];
233
+ if (fw) el.style.fontWeight = fw;
234
+ },
235
+ tracking: (el, value) => {
236
+ const ls = config.letterSpacing[value];
237
+ if (ls) el.style.letterSpacing = ls;
238
+ },
239
+ leading: (el, value) => {
240
+ const lh = config.lineHeight[value];
241
+ if (lh) el.style.lineHeight = lh;
242
+ },
243
+ uppercase: (el) => el.style.textTransform = "uppercase",
244
+ lowercase: (el) => el.style.textTransform = "lowercase",
245
+ capitalize: (el) => el.style.textTransform = "capitalize",
246
+ rounded: (el, value) => {
247
+ const r = config.borderRadius[value || "DEFAULT"];
248
+ if (r) el.style.borderRadius = r;
249
+ },
250
+ shadow: (el, value) => {
251
+ const s = config.shadows[value || "DEFAULT"];
252
+ if (s) el.style.boxShadow = s;
253
+ },
254
+ border: (el, value) => {
255
+ if (!value) {
256
+ el.style.borderWidth = config.borderWidth.DEFAULT;
257
+ el.style.borderStyle = "solid";
258
+ return;
259
+ }
260
+ if (config.borderWidth[value]) {
261
+ el.style.borderWidth = config.borderWidth[value];
262
+ el.style.borderStyle = "solid";
263
+ return;
264
+ }
265
+ const [color, shade] = value.split("-");
266
+ const c = config.colors[color]?.[shade] || config.colors[color];
267
+ if (c) {
268
+ el.style.border = `${config.borderWidth.DEFAULT} solid ${c}`;
269
+ }
270
+ },
271
+ flex: (el, value) => {
272
+ el.style.display = "flex";
273
+ if (value === "col") el.style.flexDirection = "column";
274
+ if (value === "row") el.style.flexDirection = "row";
275
+ },
276
+ justify: (el, value) => {
277
+ const map = {
278
+ start: "flex-start",
279
+ center: "center",
280
+ end: "flex-end",
281
+ between: "space-between",
282
+ around: "space-around",
283
+ evenly: "space-evenly"
284
+ };
285
+ if (map[value]) {
286
+ el.style.display = "flex";
287
+ el.style.justifyContent = map[value];
288
+ }
289
+ },
290
+ items: (el, value) => {
291
+ const map = {
292
+ start: "flex-start",
293
+ center: "center",
294
+ end: "flex-end",
295
+ stretch: "stretch",
296
+ baseline: "baseline"
297
+ };
298
+ if (map[value]) {
299
+ el.style.display = "flex";
300
+ el.style.alignItems = map[value];
301
+ }
302
+ },
303
+ grid: (el, value) => {
304
+ el.style.display = "grid";
305
+ if (value && value.startsWith("cols-")) {
306
+ const n = value.replace("cols-", "");
307
+ el.style.gridTemplateColumns = `repeat(${n}, 1fr)`;
308
+ }
309
+ },
310
+ gap: (el, value) => {
311
+ const g = config.spacing[value];
312
+ if (g) el.style.gap = g;
313
+ },
314
+ w: (el, value) => {
315
+ const named = config.widths[value];
316
+ if (named) {
317
+ el.style.width = named;
318
+ return;
319
+ }
320
+ const s = config.spacing[value];
321
+ if (s) el.style.width = s;
322
+ },
323
+ h: (el, value) => {
324
+ const named = config.heights[value];
325
+ if (named) {
326
+ el.style.height = named;
327
+ return;
328
+ }
329
+ const s = config.spacing[value];
330
+ if (s) el.style.height = s;
331
+ },
332
+ align: (el, value) => {
333
+ const a = config.textAlign[value];
334
+ if (a) el.style.textAlign = a;
335
+ },
336
+ cursor: (el, value) => {
337
+ const c = config.cursor[value];
338
+ if (c) el.style.cursor = c;
339
+ },
340
+ overflow: (el, value) => {
341
+ const o = config.overflow[value];
342
+ if (o) el.style.overflow = o;
343
+ },
344
+ opacity: (el, value) => {
345
+ el.style.opacity = value / 100;
346
+ },
347
+ relative: (el) => el.style.position = "relative",
348
+ absolute: (el) => el.style.position = "absolute",
349
+ top: (el, value) => {
350
+ const s = config.spacing[value];
351
+ if (s) el.style.top = s;
352
+ },
353
+ left: (el, value) => {
354
+ const s = config.spacing[value];
355
+ if (s) el.style.left = s;
356
+ },
357
+ z: (el, value) => {
358
+ const z = config.zIndex[value];
359
+ if (z !== void 0) el.style.zIndex = z;
360
+ },
361
+ transition: (el) => {
362
+ el.style.transition = "all 0.2s ease";
363
+ },
364
+ duration: (el, value) => {
365
+ el.style.transitionDuration = `${value}ms`;
366
+ },
367
+ ease: (el, value) => {
368
+ const t = config.transitionTiming[value];
369
+ if (t) el.style.transitionTimingFunction = t;
370
+ },
371
+ scale: (el, value) => {
372
+ el.style.transform = `scale(${value / 100})`;
373
+ },
374
+ px: (el, value) => {
375
+ const s = config.spacing[value];
376
+ if (s) {
377
+ el.style.paddingLeft = s;
378
+ el.style.paddingRight = s;
379
+ }
380
+ },
381
+ py: (el, value) => {
382
+ const s = config.spacing[value];
383
+ if (s) {
384
+ el.style.paddingTop = s;
385
+ el.style.paddingBottom = s;
386
+ }
387
+ },
388
+ mx: (el, value) => {
389
+ const s = config.spacing[value];
390
+ if (s) {
391
+ el.style.marginLeft = s;
392
+ el.style.marginRight = s;
393
+ }
394
+ },
395
+ my: (el, value) => {
396
+ const s = config.spacing[value];
397
+ if (s) {
398
+ el.style.marginTop = s;
399
+ el.style.marginBottom = s;
400
+ }
401
+ },
402
+ mt: (el, value) => {
403
+ const s = config.spacing[value];
404
+ if (s) el.style.marginTop = s;
405
+ },
406
+ mb: (el, value) => {
407
+ const s = config.spacing[value];
408
+ if (s) el.style.marginBottom = s;
409
+ },
410
+ ml: (el, value) => {
411
+ const s = config.spacing[value];
412
+ if (s) el.style.marginLeft = s;
413
+ },
414
+ mr: (el, value) => {
415
+ const s = config.spacing[value];
416
+ if (s) el.style.marginRight = s;
417
+ },
418
+ pt: (el, value) => {
419
+ const s = config.spacing[value];
420
+ if (s) el.style.paddingTop = s;
421
+ },
422
+ pb: (el, value) => {
423
+ const s = config.spacing[value];
424
+ if (s) el.style.paddingBottom = s;
425
+ },
426
+ pl: (el, value) => {
427
+ const s = config.spacing[value];
428
+ if (s) el.style.paddingLeft = s;
429
+ },
430
+ pr: (el, value) => {
431
+ const s = config.spacing[value];
432
+ if (s) el.style.paddingRight = s;
433
+ },
434
+ "space-x": (el, value) => {
435
+ const s = config.spacing[value];
436
+ if (s) {
437
+ Array.from(el.children).forEach((child, idx) => {
438
+ if (idx > 0) child.style.marginLeft = s;
439
+ });
440
+ }
441
+ },
442
+ "space-y": (el, value) => {
443
+ const s = config.spacing[value];
444
+ if (s) {
445
+ Array.from(el.children).forEach((child, idx) => {
446
+ if (idx > 0) child.style.marginTop = s;
447
+ });
448
+ }
449
+ },
450
+ "backdrop-blur": (el, value) => {
451
+ const b = config.blur[value || "DEFAULT"];
452
+ if (b) el.style.backdropFilter = `blur(${b})`;
453
+ },
454
+ "bg-opacity": (el, value) => {
455
+ const opacity = config.opacity[value];
456
+ if (opacity !== void 0) {
457
+ const bgColor = window.getComputedStyle(el).backgroundColor;
458
+ const rgbaColor = bgColor.replace(/rgba?\(/, "rgba(").replace(/\)/, `)`);
459
+ const match = rgbaColor.match(/(rgba?\([^,]+,[^,]+,[^,]+),/);
460
+ if (match) {
461
+ el.style.backgroundColor = `${match[1]}, ${opacity})`;
462
+ }
463
+ }
464
+ },
465
+ hidden: (el) => el.style.display = "none",
466
+ block: (el) => el.style.display = "block",
467
+ inline: (el) => el.style.display = "inline",
468
+ right: (el, value) => {
469
+ const s = config.spacing[value];
470
+ if (s) el.style.right = s;
471
+ },
472
+ bottom: (el, value) => {
473
+ const s = config.spacing[value];
474
+ if (s) el.style.bottom = s;
475
+ }
476
+ };
477
+ function interpretClass(element, cls) {
478
+ const parsed = parseClass(cls);
479
+ if (!parsed) return;
480
+ const { hover, prefix, value } = parsed;
481
+ const handler = handlers[prefix];
482
+ if (!handler) return;
483
+ if (!hover) {
484
+ handler(element, value);
485
+ }
486
+ if (hover === "hover") {
487
+ const original = element.style.cssText;
488
+ element.addEventListener("mouseenter", () => {
489
+ handler(element, value);
490
+ });
491
+ element.addEventListener("mouseleave", () => {
492
+ element.style.cssText = original;
493
+ });
494
+ }
495
+ }
496
+
497
+ // src/core/styler.js
498
+ function applyStyles(elements) {
499
+ elements.forEach((element) => {
500
+ element.classList.forEach((cls) => {
501
+ interpretClass(element, cls);
502
+ });
503
+ });
504
+ }
505
+
1
506
  // src/index.js
2
507
  function chaiTailwind() {
3
508
  const elements = scanDOM();
4
509
  applyStyles(elements);
5
510
  }
6
511
  var index_default = chaiTailwind;
7
- if (typeof window !== "undefined") {
8
- window.chaiTailwind = chaiTailwind;
9
- }
10
512
  export {
11
513
  index_default as default
12
514
  };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "chai-tailwind-js",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "main": "dist/chai-tailwind.js",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "npm run build:esm && npm run build:global",
8
8
  "build:esm": "esbuild src/index.js --bundle --format=esm --outfile=dist/chai-tailwind.js",
9
- "build:global": "esbuild src/index.js --bundle --format=iife --global-name=chaiTailwind --outfile=dist/chai-tailwind.global.js"
9
+ "build:global": "esbuild src/browser.js --bundle --format=iife --outfile=dist/chai-tailwind.global.js"
10
10
  },
11
11
  "keywords": [],
12
12
  "author": "",