create-prisma-php-app 2.0.0-beta.14 → 2.0.0-beta.16

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.
@@ -9,7 +9,6 @@ class TwMerge
9
9
  private static $classGroupPatterns = [
10
10
  // **General Padding classes**
11
11
  "p" => "/^p-/",
12
-
13
12
  // **Specific Padding classes**
14
13
  "pt" => "/^pt-/",
15
14
  "pr" => "/^pr-/",
@@ -17,7 +16,6 @@ class TwMerge
17
16
  "pl" => "/^pl-/",
18
17
  "px" => "/^px-/",
19
18
  "py" => "/^py-/",
20
-
21
19
  // **Margin classes**
22
20
  "m" => "/^m-/",
23
21
  "mt" => "/^mt-/",
@@ -26,60 +24,42 @@ class TwMerge
26
24
  "ml" => "/^ml-/",
27
25
  "mx" => "/^mx-/",
28
26
  "my" => "/^my-/",
29
-
30
27
  // **Background color classes**
31
28
  "bg" => "/^bg-/",
32
-
33
- // **Text size classes
29
+ // **Text size classes**
34
30
  "text-size" => '/^text-(xs|sm|base|lg|xl|[2-9]xl)$/',
35
-
36
31
  // **Text alignment classes**
37
32
  "text-alignment" => '/^text-(left|center|right|justify)$/',
38
-
39
- // **Text color classes
33
+ // **Text color classes**
40
34
  "text-color" => '/^text-(?!xs$|sm$|base$|lg$|xl$|[2-9]xl$).+$/',
41
-
42
35
  // **Text transform classes**
43
- "text-transform" =>
44
- '/^text-(uppercase|lowercase|capitalize|normal-case)$/',
45
-
36
+ "text-transform" => '/^text-(uppercase|lowercase|capitalize|normal-case)$/',
46
37
  // **Text decoration classes**
47
38
  "text-decoration" => '/^text-(underline|line-through|no-underline)$/',
48
-
49
39
  // **Border width classes**
50
40
  "border-width" => '/^border(-[0-9]+)?$/',
51
-
52
41
  // **Border color classes**
53
42
  "border-color" => "/^border-(?![0-9])/",
54
-
55
43
  // **Border radius classes**
56
44
  "rounded" => '/^rounded(-.*)?$/',
57
-
58
45
  // **Font weight classes**
59
- "font" =>
60
- '/^font-(thin|extralight|light|normal|medium|semibold|bold|extrabold|black)$/',
61
-
46
+ "font" => '/^font-(thin|extralight|light|normal|medium|semibold|bold|extrabold|black)$/',
62
47
  // **Hover background color classes**
63
48
  "hover:bg" => "/^hover:bg-/",
64
-
65
49
  // **Hover text color classes**
66
50
  "hover:text" => "/^hover:text-/",
67
-
68
51
  // **Transition classes**
69
52
  "transition" => '/^transition(-[a-z]+)?$/',
70
-
71
- // **Opacity classes
53
+ // **Opacity classes**
72
54
  "opacity" => '/^opacity(-[0-9]+)?$/',
73
-
74
55
  // **Flexbox alignment classes**
75
56
  "justify" => "/^justify-(start|end|center|between|around|evenly)$/",
76
-
77
57
  // **Flexbox alignment classes**
78
58
  "items" => "/^items-(start|end|center|baseline|stretch)$/",
79
-
80
59
  // **Width classes**
81
60
  "w" => "/^w-(full|[0-9]+|\\[.+\\])$/",
82
-
61
+ // **Max-width classes**
62
+ "max-w" => '/^max-w-(full|[0-9]+|\\[.+\\]|[a-zA-Z]+)$/',
83
63
  // **Other utility classes can be added here**
84
64
  ];
85
65
 
@@ -92,7 +72,6 @@ class TwMerge
92
72
  "pr" => ["pr"],
93
73
  "pb" => ["pb"],
94
74
  "pl" => ["pl"],
95
-
96
75
  // **Margin conflict groups**
97
76
  "m" => ["m", "mx", "my", "mt", "mr", "mb", "ml"],
98
77
  "mx" => ["mx", "ml", "mr"],
@@ -101,57 +80,37 @@ class TwMerge
101
80
  "mr" => ["mr"],
102
81
  "mb" => ["mb"],
103
82
  "ml" => ["ml"],
104
-
105
83
  // **Border width conflict group**
106
84
  "border-width" => ["border-width"],
107
-
108
85
  // **Border color conflict group**
109
86
  "border-color" => ["border-color"],
110
-
111
87
  // **Text size conflict group**
112
88
  "text-size" => ["text-size"],
113
-
114
89
  // **Text color conflict group**
115
90
  "text-color" => ["text-color"],
116
-
117
91
  // **Text alignment conflict group**
118
92
  "text-alignment" => ["text-alignment"],
119
-
120
93
  // **Text transform conflict group**
121
94
  "text-transform" => ["text-transform"],
122
-
123
95
  // **Text decoration conflict group**
124
96
  "text-decoration" => ["text-decoration"],
125
-
126
- // **Opacity conflict group
97
+ // **Opacity conflict group**
127
98
  "opacity" => ["opacity"],
128
-
129
- // **Flexbox alignment conflict group**
99
+ // **Flexbox alignment conflict groups**
130
100
  "justify" => ["justify"],
131
-
132
101
  // **Flexbox alignment conflict group**
133
102
  "items" => ["items"],
134
-
135
103
  // **Width conflict group**
136
- "w" => ["w"],
137
-
104
+ "w" => ["w"], // Only conflicts with other width classes.
105
+ // **Max-width conflict group**
106
+ "max-w" => ["max-w"],
138
107
  // **Add other conflict groups as needed**
139
108
  ];
140
109
 
141
110
  /**
142
111
  * Merges multiple CSS class strings or arrays of CSS class strings into a single, optimized CSS class string.
143
112
  *
144
- * This method processes the provided classes, which can be either strings or arrays of strings, removes
145
- * duplicate or conflicting classes, and prioritizes the last occurrence of a class. It splits class strings
146
- * by whitespace, handles conflicting class groups, and ensures a clean and well-formatted output.
147
- *
148
- * ### Features:
149
- * - Accepts individual class strings or arrays of class strings.
150
- * - Automatically handles arrays by flattening them into individual strings.
151
- * - Removes duplicate or conflicting classes based on class groups.
152
- * - Combines all classes into a single string, properly formatted and optimized.
153
- *
154
- * @param string|array ...$classes The CSS classes to be merged. Each argument can be a string or an array of strings.
113
+ * @param string|array ...$classes The CSS classes to be merged.
155
114
  * @return string A single CSS class string with duplicates and conflicts resolved.
156
115
  */
157
116
  public static function mergeClasses(string|array ...$classes): string
@@ -159,20 +118,18 @@ class TwMerge
159
118
  $classArray = [];
160
119
 
161
120
  foreach ($classes as $class) {
162
- // Handle arrays by flattening them into strings
121
+ // Handle arrays by flattening them into strings.
163
122
  $classList = is_array($class) ? $class : [$class];
164
123
  foreach ($classList as $item) {
165
124
  if (!empty(trim($item))) {
166
- // Split the classes by any whitespace characters
125
+ // Split the classes by any whitespace characters.
167
126
  $splitClasses = preg_split("/\s+/", $item);
168
127
  foreach ($splitClasses as $individualClass) {
169
128
  $classKey = self::getClassGroup($individualClass);
170
129
 
171
- // If the class is non-responsive (no colon), remove any responsive variants for the same base
130
+ // If the class is non-responsive (no colon), remove any responsive variants for the same base.
172
131
  if (strpos($classKey, ':') === false) {
173
- // The base group is the class key itself (e.g. "justify")
174
132
  $baseGroup = $classKey;
175
- // Remove any entries that end with the same base group but have a prefix (e.g. "sm:justify")
176
133
  foreach ($classArray as $existingKey => $existingClass) {
177
134
  if ($existingKey !== $baseGroup && substr($existingKey, -strlen($baseGroup)) === $baseGroup) {
178
135
  unset($classArray[$existingKey]);
@@ -180,67 +137,54 @@ class TwMerge
180
137
  }
181
138
  }
182
139
 
183
- // Get the conflicting keys and remove them
140
+ // Remove conflicting classes based on the conflict groups.
184
141
  $conflictingKeys = self::getConflictingKeys($classKey);
185
-
186
- // Remove any conflicting classes
187
142
  foreach ($conflictingKeys as $key) {
188
143
  unset($classArray[$key]);
189
144
  }
190
145
 
191
- // Update the array, prioritizing the last occurrence
146
+ // Update the array, prioritizing the last occurrence.
192
147
  $classArray[$classKey] = $individualClass;
193
148
  }
194
149
  }
195
150
  }
196
151
  }
197
152
 
198
- // Combine the final classes into a single string
153
+ // Combine the final classes into a single string.
199
154
  return implode(" ", array_values($classArray));
200
155
  }
201
156
 
202
157
  private static function getClassGroup($class)
203
158
  {
204
- // Match optional prefixes (responsive and variants)
159
+ // Match optional prefixes (responsive and variants).
205
160
  $pattern = '/^((?:[a-z-]+:)*)(.+)$/';
206
-
207
161
  if (preg_match($pattern, $class, $matches)) {
208
- $prefixes = $matches[1]; // Includes responsive and variant prefixes
209
- $utilityClass = $matches[2]; // The utility class
162
+ $prefixes = $matches[1];
163
+ $utilityClass = $matches[2];
210
164
 
211
- // Now match utilityClass against patterns
165
+ // Match the utilityClass against patterns.
212
166
  foreach (self::$classGroupPatterns as $groupKey => $regex) {
213
167
  if (preg_match($regex, $utilityClass)) {
214
168
  return $prefixes . $groupKey;
215
169
  }
216
170
  }
217
-
218
- // If no match, use the full class
171
+ // If no match, use the full class.
219
172
  return $prefixes . $utilityClass;
220
173
  }
221
-
222
- // For classes without a recognizable prefix, return the class itself
174
+ // For classes without a recognizable prefix, return the class itself.
223
175
  return $class;
224
176
  }
225
177
 
226
178
  private static function getConflictingKeys($classKey)
227
179
  {
228
- // Remove any responsive or variant prefixes
180
+ // Remove any responsive or variant prefixes.
229
181
  $baseClassKey = preg_replace("/^(?:[a-z-]+:)+/", "", $classKey);
230
-
231
- // Check for conflicts
232
182
  if (isset(self::$conflictGroups[$baseClassKey])) {
233
- // Add responsive and variant prefixes back to the conflicting keys
234
- $prefix = preg_replace(
235
- "/" . preg_quote($baseClassKey, "/") . '$/',
236
- "",
237
- $classKey
238
- );
183
+ $prefix = preg_replace("/" . preg_quote($baseClassKey, "/") . '$/', "", $classKey);
239
184
  return array_map(function ($conflict) use ($prefix) {
240
185
  return $prefix . $conflict;
241
186
  }, self::$conflictGroups[$baseClassKey]);
242
187
  }
243
-
244
188
  return [$classKey];
245
189
  }
246
190
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "2.0.0-beta.14",
3
+ "version": "2.0.0-beta.16",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",