@itamarshdev/reactwind 0.1.1 → 1.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.
@@ -0,0 +1,245 @@
1
+ // src/runtime.ts
2
+ var LAYOUT_PROPS = [
3
+ "flex",
4
+ "grid",
5
+ "hidden",
6
+ "block",
7
+ "inline",
8
+ "inline-block",
9
+ "inline-flex",
10
+ "inline-grid",
11
+ "relative",
12
+ "absolute",
13
+ "fixed",
14
+ "sticky",
15
+ "static",
16
+ "flex-row",
17
+ "flex-col",
18
+ "flex-wrap",
19
+ "flex-nowrap",
20
+ "items-center",
21
+ "items-start",
22
+ "items-end",
23
+ "justify-center",
24
+ "justify-between",
25
+ "justify-start",
26
+ "justify-end",
27
+ "grow",
28
+ "shrink",
29
+ "italic",
30
+ "not-italic",
31
+ "underline",
32
+ "uppercase",
33
+ "lowercase",
34
+ "capitalize",
35
+ "truncate",
36
+ "visible",
37
+ "invisible",
38
+ "collapse",
39
+ "pointer-events-none",
40
+ "pointer-events-auto",
41
+ "sr-only",
42
+ "not-sr-only"
43
+ ];
44
+ var VALUE_PROPS_MAP = {
45
+ bg: "bg",
46
+ text: "text",
47
+ border: "border",
48
+ fill: "fill",
49
+ stroke: "stroke",
50
+ p: "p",
51
+ m: "m",
52
+ px: "px",
53
+ py: "py",
54
+ mx: "mx",
55
+ my: "my",
56
+ gap: "gap",
57
+ w: "w",
58
+ h: "h",
59
+ rounded: "rounded",
60
+ shadow: "shadow",
61
+ font: "font",
62
+ z: "z",
63
+ mb: "mb",
64
+ mt: "mt",
65
+ ml: "ml",
66
+ mr: "mr",
67
+ pb: "pb",
68
+ pt: "pt",
69
+ pl: "pl",
70
+ pr: "pr",
71
+ tracking: "tracking",
72
+ leading: "leading",
73
+ "max-w": "max-w",
74
+ "min-w": "min-w",
75
+ "min-h": "min-h",
76
+ "max-h": "max-h",
77
+ "grid-cols": "grid-cols",
78
+ "col-span": "col-span",
79
+ "row-span": "row-span",
80
+ "grid-rows": "grid-rows",
81
+ "items": "items",
82
+ "justify": "justify",
83
+ "self": "self",
84
+ "place-content": "place-content",
85
+ "place-items": "place-items",
86
+ "place-self": "place-self",
87
+ "order": "order",
88
+ overflow: "overflow",
89
+ decoration: "decoration",
90
+ whitespace: "whitespace",
91
+ break: "break",
92
+ content: "content",
93
+ opacity: "opacity",
94
+ "bg-opacity": "bg-opacity",
95
+ "text-opacity": "text-opacity",
96
+ "border-opacity": "border-opacity",
97
+ ring: "ring",
98
+ "ring-offset": "ring-offset",
99
+ outline: "outline",
100
+ divide: "divide",
101
+ "mix-blend": "mix-blend",
102
+ "backdrop-blur": "backdrop-blur",
103
+ blur: "blur",
104
+ brightness: "brightness",
105
+ contrast: "contrast",
106
+ grayscale: "grayscale",
107
+ "hue-rotate": "hue-rotate",
108
+ invert: "invert",
109
+ saturate: "saturate",
110
+ sepia: "sepia",
111
+ "drop-shadow": "drop-shadow",
112
+ transition: "transition",
113
+ duration: "duration",
114
+ ease: "ease",
115
+ delay: "delay",
116
+ animate: "animate",
117
+ cursor: "cursor",
118
+ "pointer-events": "pointer-events",
119
+ resize: "resize",
120
+ select: "select",
121
+ scale: "scale",
122
+ rotate: "rotate",
123
+ translate: "translate",
124
+ skew: "skew",
125
+ origin: "origin"
126
+ };
127
+ var MODIFIERS = [
128
+ "hover",
129
+ "focus",
130
+ "active",
131
+ "visited",
132
+ "disabled",
133
+ "group-hover",
134
+ "group-focus",
135
+ "focus-within",
136
+ "focus-visible",
137
+ "target",
138
+ "first",
139
+ "last",
140
+ "only",
141
+ "odd",
142
+ "even",
143
+ "first-of-type",
144
+ "last-of-type",
145
+ "only-of-type",
146
+ "empty",
147
+ "checked",
148
+ "indeterminate",
149
+ "default",
150
+ "required",
151
+ "valid",
152
+ "invalid",
153
+ "in-range",
154
+ "out-of-range",
155
+ "placeholder-shown",
156
+ "autofill",
157
+ "read-only",
158
+ "open",
159
+ // Responsive breakpoints
160
+ "sm",
161
+ "md",
162
+ "lg",
163
+ "xl",
164
+ "2xl",
165
+ // Dark mode
166
+ "dark",
167
+ // Print
168
+ "print"
169
+ ];
170
+ var joinClassNames = (classNames) => {
171
+ if (!classNames || classNames.length === 0) {
172
+ return "";
173
+ }
174
+ return classNames.filter(Boolean).join(" ");
175
+ };
176
+ var withClassNames = (props) => {
177
+ if (!props) {
178
+ return props;
179
+ }
180
+ const hasClassNames = "classNames" in props;
181
+ const hasLayoutProps = LAYOUT_PROPS.some((k) => k in props);
182
+ const hasValueProps = Object.keys(VALUE_PROPS_MAP).some((k) => k in props);
183
+ const propsKeys = Object.keys(props);
184
+ const hasModifiers = propsKeys.some((key) => {
185
+ return MODIFIERS.some((mod) => key.startsWith(`${mod}-`));
186
+ });
187
+ if (!hasClassNames && !hasLayoutProps && !hasValueProps && !hasModifiers) {
188
+ return props;
189
+ }
190
+ const { classNames, className, ...rest } = props;
191
+ const generatedClasses = [];
192
+ const cleanRest = { ...rest };
193
+ for (const prop of LAYOUT_PROPS) {
194
+ if (prop in cleanRest && cleanRest[prop] === true) {
195
+ generatedClasses.push(prop);
196
+ delete cleanRest[prop];
197
+ }
198
+ }
199
+ for (const [prop, prefix] of Object.entries(VALUE_PROPS_MAP)) {
200
+ if (prop in cleanRest) {
201
+ const value = cleanRest[prop];
202
+ if (typeof value === "string" || typeof value === "number") {
203
+ generatedClasses.push(`${prefix}-${value}`);
204
+ delete cleanRest[prop];
205
+ } else if (value === true && (prop === "shadow" || prop === "rounded" || prop === "border" || prop === "transition")) {
206
+ generatedClasses.push(prop);
207
+ delete cleanRest[prop];
208
+ }
209
+ }
210
+ }
211
+ Object.keys(cleanRest).forEach((key) => {
212
+ const firstHyphenIndex = key.indexOf("-");
213
+ if (firstHyphenIndex === -1) return;
214
+ const modifier = key.substring(0, firstHyphenIndex);
215
+ if (MODIFIERS.includes(modifier)) {
216
+ const restKey = key.substring(firstHyphenIndex + 1);
217
+ const value = cleanRest[key];
218
+ if (restKey in VALUE_PROPS_MAP) {
219
+ const prefix = VALUE_PROPS_MAP[restKey];
220
+ if (typeof value === "string" || typeof value === "number") {
221
+ generatedClasses.push(`${modifier}:${prefix}-${value}`);
222
+ delete cleanRest[key];
223
+ } else if (value === true && (restKey === "shadow" || restKey === "rounded" || restKey === "border")) {
224
+ generatedClasses.push(`${modifier}:${restKey}`);
225
+ delete cleanRest[key];
226
+ }
227
+ } else if (LAYOUT_PROPS.includes(restKey)) {
228
+ if (value === true) {
229
+ generatedClasses.push(`${modifier}:${restKey}`);
230
+ delete cleanRest[key];
231
+ }
232
+ }
233
+ }
234
+ });
235
+ const joined = joinClassNames(classNames || []);
236
+ const merged = [className, ...generatedClasses, joined].filter(Boolean).join(" ");
237
+ return {
238
+ ...cleanRest,
239
+ ...merged ? { className: merged } : {}
240
+ };
241
+ };
242
+
243
+ export {
244
+ withClassNames
245
+ };
package/dist/index.cjs CHANGED
@@ -100,6 +100,17 @@ var VALUE_PROPS_MAP = {
100
100
  "min-w": "min-w",
101
101
  "min-h": "min-h",
102
102
  "max-h": "max-h",
103
+ "grid-cols": "grid-cols",
104
+ "col-span": "col-span",
105
+ "row-span": "row-span",
106
+ "grid-rows": "grid-rows",
107
+ "items": "items",
108
+ "justify": "justify",
109
+ "self": "self",
110
+ "place-content": "place-content",
111
+ "place-items": "place-items",
112
+ "place-self": "place-self",
113
+ "order": "order",
103
114
  overflow: "overflow",
104
115
  decoration: "decoration",
105
116
  whitespace: "whitespace",
@@ -107,6 +118,8 @@ var VALUE_PROPS_MAP = {
107
118
  content: "content",
108
119
  opacity: "opacity",
109
120
  "bg-opacity": "bg-opacity",
121
+ "text-opacity": "text-opacity",
122
+ "border-opacity": "border-opacity",
110
123
  ring: "ring",
111
124
  "ring-offset": "ring-offset",
112
125
  outline: "outline",
@@ -135,14 +148,140 @@ var VALUE_PROPS_MAP = {
135
148
  rotate: "rotate",
136
149
  translate: "translate",
137
150
  skew: "skew",
138
- origin: "origin"
151
+ origin: "origin",
152
+ // Layout & Position
153
+ top: "top",
154
+ right: "right",
155
+ bottom: "bottom",
156
+ left: "left",
157
+ inset: "inset",
158
+ "inset-x": "inset-x",
159
+ "inset-y": "inset-y",
160
+ aspect: "aspect",
161
+ columns: "columns",
162
+ float: "float",
163
+ clear: "clear",
164
+ // Flexbox & Grid
165
+ basis: "basis",
166
+ "gap-x": "gap-x",
167
+ "gap-y": "gap-y",
168
+ "auto-cols": "auto-cols",
169
+ "auto-rows": "auto-rows",
170
+ "grid-flow": "grid-flow",
171
+ "space-x": "space-x",
172
+ "space-y": "space-y",
173
+ "justify-items": "justify-items",
174
+ "justify-self": "justify-self",
175
+ // Sizing
176
+ size: "size",
177
+ // Borders
178
+ "border-t": "border-t",
179
+ "border-r": "border-r",
180
+ "border-b": "border-b",
181
+ "border-l": "border-l",
182
+ "border-x": "border-x",
183
+ "border-y": "border-y",
184
+ "rounded-t": "rounded-t",
185
+ "rounded-r": "rounded-r",
186
+ "rounded-b": "rounded-b",
187
+ "rounded-l": "rounded-l",
188
+ "rounded-tl": "rounded-tl",
189
+ "rounded-tr": "rounded-tr",
190
+ "rounded-bl": "rounded-bl",
191
+ "rounded-br": "rounded-br",
192
+ "border-style": "border",
193
+ // Typography
194
+ "text-align": "text",
195
+ align: "align",
196
+ "line-clamp": "line-clamp",
197
+ list: "list",
198
+ indent: "indent",
199
+ // Backgrounds & Gradients
200
+ "bg-gradient": "bg-gradient",
201
+ from: "from",
202
+ via: "via",
203
+ to: "to",
204
+ "bg-size": "bg",
205
+ "bg-position": "bg",
206
+ "bg-repeat": "bg",
207
+ // Interactivity
208
+ scroll: "scroll",
209
+ snap: "snap",
210
+ touch: "touch",
211
+ "will-change": "will-change",
212
+ caret: "caret",
213
+ accent: "accent",
214
+ // SVG
215
+ "stroke-width": "stroke"
139
216
  };
217
+ var MODIFIERS = [
218
+ "hover",
219
+ "focus",
220
+ "active",
221
+ "visited",
222
+ "disabled",
223
+ "group-hover",
224
+ "group-focus",
225
+ "focus-within",
226
+ "focus-visible",
227
+ "target",
228
+ "first",
229
+ "last",
230
+ "only",
231
+ "odd",
232
+ "even",
233
+ "first-of-type",
234
+ "last-of-type",
235
+ "only-of-type",
236
+ "empty",
237
+ "checked",
238
+ "indeterminate",
239
+ "default",
240
+ "required",
241
+ "valid",
242
+ "invalid",
243
+ "in-range",
244
+ "out-of-range",
245
+ "placeholder-shown",
246
+ "autofill",
247
+ "read-only",
248
+ "open",
249
+ // Responsive breakpoints
250
+ "sm",
251
+ "md",
252
+ "lg",
253
+ "xl",
254
+ "2xl",
255
+ // Dark mode
256
+ "dark",
257
+ // Print
258
+ "print"
259
+ ];
260
+ var BOOLEAN_VALUE_PROPS = ["shadow", "rounded", "border", "transition", "ring", "outline"];
140
261
  var joinClassNames = (classNames) => {
141
262
  if (!classNames || classNames.length === 0) {
142
263
  return "";
143
264
  }
144
265
  return classNames.filter(Boolean).join(" ");
145
266
  };
267
+ var processModifierObject = (modifier, obj, classes) => {
268
+ for (const [key, value] of Object.entries(obj)) {
269
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
270
+ if (MODIFIERS.includes(key)) {
271
+ processModifierObject(`${modifier}:${key}`, value, classes);
272
+ }
273
+ } else if (key in VALUE_PROPS_MAP) {
274
+ const prefix = VALUE_PROPS_MAP[key];
275
+ if (typeof value === "string" || typeof value === "number") {
276
+ classes.push(`${modifier}:${prefix}-${value}`);
277
+ } else if (value === true && BOOLEAN_VALUE_PROPS.includes(key)) {
278
+ classes.push(`${modifier}:${key}`);
279
+ }
280
+ } else if (LAYOUT_PROPS.includes(key) && value === true) {
281
+ classes.push(`${modifier}:${key}`);
282
+ }
283
+ }
284
+ };
146
285
  var withClassNames = (props) => {
147
286
  if (!props) {
148
287
  return props;
@@ -150,7 +289,15 @@ var withClassNames = (props) => {
150
289
  const hasClassNames = "classNames" in props;
151
290
  const hasLayoutProps = LAYOUT_PROPS.some((k) => k in props);
152
291
  const hasValueProps = Object.keys(VALUE_PROPS_MAP).some((k) => k in props);
153
- if (!hasClassNames && !hasLayoutProps && !hasValueProps) {
292
+ const propsKeys = Object.keys(props);
293
+ const hasHyphenatedModifiers = propsKeys.some((key) => {
294
+ return MODIFIERS.some((mod) => key.startsWith(`${mod}-`));
295
+ });
296
+ const hasObjectModifiers = propsKeys.some((key) => {
297
+ return MODIFIERS.includes(key) && typeof props[key] === "object" && props[key] !== null;
298
+ });
299
+ const hasModifiers = hasHyphenatedModifiers || hasObjectModifiers;
300
+ if (!hasClassNames && !hasLayoutProps && !hasValueProps && !hasModifiers) {
154
301
  return props;
155
302
  }
156
303
  const { classNames, className, ...rest } = props;
@@ -168,12 +315,45 @@ var withClassNames = (props) => {
168
315
  if (typeof value === "string" || typeof value === "number") {
169
316
  generatedClasses.push(`${prefix}-${value}`);
170
317
  delete cleanRest[prop];
171
- } else if (value === true && (prop === "shadow" || prop === "rounded")) {
318
+ } else if (value === true && BOOLEAN_VALUE_PROPS.includes(prop)) {
172
319
  generatedClasses.push(prop);
173
320
  delete cleanRest[prop];
174
321
  }
175
322
  }
176
323
  }
324
+ for (const modifier of MODIFIERS) {
325
+ if (modifier in cleanRest) {
326
+ const value = cleanRest[modifier];
327
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
328
+ processModifierObject(modifier, value, generatedClasses);
329
+ delete cleanRest[modifier];
330
+ }
331
+ }
332
+ }
333
+ Object.keys(cleanRest).forEach((key) => {
334
+ const firstHyphenIndex = key.indexOf("-");
335
+ if (firstHyphenIndex === -1) return;
336
+ const modifier = key.substring(0, firstHyphenIndex);
337
+ if (MODIFIERS.includes(modifier)) {
338
+ const restKey = key.substring(firstHyphenIndex + 1);
339
+ const value = cleanRest[key];
340
+ if (restKey in VALUE_PROPS_MAP) {
341
+ const prefix = VALUE_PROPS_MAP[restKey];
342
+ if (typeof value === "string" || typeof value === "number") {
343
+ generatedClasses.push(`${modifier}:${prefix}-${value}`);
344
+ delete cleanRest[key];
345
+ } else if (value === true && BOOLEAN_VALUE_PROPS.includes(restKey)) {
346
+ generatedClasses.push(`${modifier}:${restKey}`);
347
+ delete cleanRest[key];
348
+ }
349
+ } else if (LAYOUT_PROPS.includes(restKey)) {
350
+ if (value === true) {
351
+ generatedClasses.push(`${modifier}:${restKey}`);
352
+ delete cleanRest[key];
353
+ }
354
+ }
355
+ }
356
+ });
177
357
  const joined = joinClassNames(classNames || []);
178
358
  const merged = [className, ...generatedClasses, joined].filter(Boolean).join(" ");
179
359
  return {
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  withClassNames
3
- } from "./chunk-WXTVOZ4W.js";
3
+ } from "./chunk-KAWYX6WW.js";
4
4
  export {
5
5
  withClassNames
6
6
  };