create-prisma-php-app 3.3.14 → 3.4.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.
|
@@ -68,7 +68,7 @@ class PHPX implements IPHPX
|
|
|
68
68
|
unset($chunk);
|
|
69
69
|
|
|
70
70
|
$merged = PrismaPHPSettings::$option->tailwindcss
|
|
71
|
-
? TwMerge::
|
|
71
|
+
? TwMerge::merge(...$all)
|
|
72
72
|
: $this->mergeClasses(...$all);
|
|
73
73
|
|
|
74
74
|
return str_replace(array_keys($expr), array_values($expr), $merged);
|
|
@@ -6,8 +6,6 @@ namespace Lib\PHPX;
|
|
|
6
6
|
|
|
7
7
|
class TwMerge
|
|
8
8
|
{
|
|
9
|
-
private const IMPORTANT_MODIFIER = '!';
|
|
10
|
-
|
|
11
9
|
private static array $classGroups = [
|
|
12
10
|
// Layout
|
|
13
11
|
'aspect' => ['aspect-auto', 'aspect-square', 'aspect-video', '/^aspect-\[.+\]$/'],
|
|
@@ -92,13 +90,13 @@ class TwMerge
|
|
|
92
90
|
'space-y' => ['/^-?space-y-(\d+(\.\d+)?|px|reverse|\[.+\])$/'],
|
|
93
91
|
|
|
94
92
|
// Sizing
|
|
95
|
-
'w' => ['/^w-(
|
|
96
|
-
'min-w' => ['/^min-w-(
|
|
97
|
-
'max-w' => ['/^max-w-(
|
|
98
|
-
'h' => ['/^h-(
|
|
99
|
-
'min-h' => ['/^min-h-(
|
|
100
|
-
'max-h' => ['/^max-h-(
|
|
101
|
-
'size' => ['/^size-(
|
|
93
|
+
'w' => ['/^w-(?!$).+$/'],
|
|
94
|
+
'min-w' => ['/^min-w-(?!$).+$/'],
|
|
95
|
+
'max-w' => ['/^max-w-(?!$).+$/'],
|
|
96
|
+
'h' => ['/^h-(?!$).+$/'],
|
|
97
|
+
'min-h' => ['/^min-h-(?!$).+$/'],
|
|
98
|
+
'max-h' => ['/^max-h-(?!$).+$/'],
|
|
99
|
+
'size' => ['/^size-(?!$).+$/'],
|
|
102
100
|
|
|
103
101
|
// Typography
|
|
104
102
|
'font-family' => ['/^font-(sans|serif|mono|\[.+\])$/'],
|
|
@@ -114,9 +112,9 @@ class TwMerge
|
|
|
114
112
|
'list-style-position' => ['/^list-(inside|outside)$/'],
|
|
115
113
|
'list-style-type' => ['/^list-(none|disc|decimal|\[.+\])$/'],
|
|
116
114
|
'text-align' => ['/^text-(left|center|right|justify|start|end)$/'],
|
|
117
|
-
'text-color' => ['/^text-(
|
|
115
|
+
'text-color' => ['/^text-(?!xs$|sm$|base$|lg$|xl$|[2-9]xl$).+$/'],
|
|
118
116
|
'text-decoration' => ['underline', 'overline', 'line-through', 'no-underline'],
|
|
119
|
-
'text-decoration-color' => ['/^decoration-(
|
|
117
|
+
'text-decoration-color' => ['/^decoration-(?!auto$|from-font$|\d+$|px$).+$/'],
|
|
120
118
|
'text-decoration-style' => ['/^decoration-(solid|double|dotted|dashed|wavy)$/'],
|
|
121
119
|
'text-decoration-thickness' => ['/^decoration-(auto|from-font|\d+|px|\[.+\])$/'],
|
|
122
120
|
'text-underline-offset' => ['/^underline-offset-(auto|\d+|px|\[.+\])$/'],
|
|
@@ -132,15 +130,15 @@ class TwMerge
|
|
|
132
130
|
// Backgrounds
|
|
133
131
|
'bg-attachment' => ['/^bg-(fixed|local|scroll)$/'],
|
|
134
132
|
'bg-clip' => ['/^bg-clip-(border|padding|content|text)$/'],
|
|
135
|
-
'bg-color' => ['/^bg-(
|
|
133
|
+
'bg-color' => ['/^bg-(?!fixed$|local$|scroll$|clip-|origin-|no-repeat$|repeat|auto$|cover$|contain$|none$|gradient-to-).+$/'],
|
|
136
134
|
'bg-origin' => ['/^bg-origin-(border|padding|content)$/'],
|
|
137
135
|
'bg-position' => ['/^bg-(bottom|center|left|left-bottom|left-top|right|right-bottom|right-top|top|\[.+\])$/'],
|
|
138
136
|
'bg-repeat' => ['/^bg-(no-repeat|repeat|repeat-x|repeat-y|repeat-round|repeat-space)$/'],
|
|
139
137
|
'bg-size' => ['/^bg-(auto|cover|contain|\[.+\])$/'],
|
|
140
138
|
'bg-image' => ['/^bg-(none|gradient-to-(t|tr|r|br|b|bl|l|tl)|\[.+\])$/'],
|
|
141
|
-
'gradient-from' => ['/^from
|
|
142
|
-
'gradient-via' => ['/^via
|
|
143
|
-
'gradient-to' => ['/^to
|
|
139
|
+
'gradient-from' => ['/^from-.+$/'],
|
|
140
|
+
'gradient-via' => ['/^via-.+$/'],
|
|
141
|
+
'gradient-to' => ['/^to-.+$/'],
|
|
144
142
|
|
|
145
143
|
// Borders
|
|
146
144
|
'rounded' => ['/^rounded(-(\w+))?(-(\d+(\.\d+)?|px|full|\[.+\]))?$/'],
|
|
@@ -151,24 +149,24 @@ class TwMerge
|
|
|
151
149
|
'border-w-r' => ['/^border-r(-(\d+|px|\[.+\]))?$/'],
|
|
152
150
|
'border-w-b' => ['/^border-b(-(\d+|px|\[.+\]))?$/'],
|
|
153
151
|
'border-w-l' => ['/^border-l(-(\d+|px|\[.+\]))?$/'],
|
|
154
|
-
'border-color' => ['/^border(-[trbl])
|
|
152
|
+
'border-color' => ['/^border(-[trbl])?-.+$/'],
|
|
155
153
|
'border-style' => ['/^border-(solid|dashed|dotted|double|hidden|none)$/'],
|
|
156
154
|
'divide-x' => ['/^divide-x(-(\d+|px|reverse|\[.+\]))?$/'],
|
|
157
155
|
'divide-y' => ['/^divide-y(-(\d+|px|reverse|\[.+\]))?$/'],
|
|
158
|
-
'divide-color' => ['/^divide
|
|
156
|
+
'divide-color' => ['/^divide-.+$/'],
|
|
159
157
|
'divide-style' => ['/^divide-(solid|dashed|dotted|double|none)$/'],
|
|
160
158
|
'outline-w' => ['/^outline(-(\d+|px|\[.+\]))?$/'],
|
|
161
|
-
'outline-color' => ['/^outline
|
|
159
|
+
'outline-color' => ['/^outline-.+$/'],
|
|
162
160
|
'outline-style' => ['/^outline-(none|solid|dashed|dotted|double)$/'],
|
|
163
161
|
'outline-offset' => ['/^outline-offset-(\d+|px|\[.+\])$/'],
|
|
164
162
|
'ring-w' => ['/^ring(-(\d+|px|inset|\[.+\]))?$/'],
|
|
165
|
-
'ring-color' => ['/^ring
|
|
163
|
+
'ring-color' => ['/^ring-.+$/'],
|
|
166
164
|
'ring-offset-w' => ['/^ring-offset-(\d+|px|\[.+\])$/'],
|
|
167
|
-
'ring-offset-color' => ['/^ring-offset
|
|
165
|
+
'ring-offset-color' => ['/^ring-offset-.+$/'],
|
|
168
166
|
|
|
169
167
|
// Effects
|
|
170
168
|
'shadow' => ['/^shadow(-(\w+|\[.+\]))?$/'],
|
|
171
|
-
'shadow-color' => ['/^shadow
|
|
169
|
+
'shadow-color' => ['/^shadow-.+$/'],
|
|
172
170
|
'opacity' => ['/^opacity-(\d+|\[.+\])$/'],
|
|
173
171
|
'mix-blend' => ['/^mix-blend-(normal|multiply|screen|overlay|darken|lighten|color-dodge|color-burn|hard-light|soft-light|difference|exclusion|hue|saturation|color|luminosity|plus-lighter)$/'],
|
|
174
172
|
'bg-blend' => ['/^bg-blend-(normal|multiply|screen|overlay|darken|lighten|color-dodge|color-burn|hard-light|soft-light|difference|exclusion|hue|saturation|color|luminosity)$/'],
|
|
@@ -210,10 +208,10 @@ class TwMerge
|
|
|
210
208
|
'transform-origin' => ['/^origin-(center|top|top-right|right|bottom-right|bottom|bottom-left|left|top-left|\[.+\])$/'],
|
|
211
209
|
|
|
212
210
|
// Interactivity
|
|
213
|
-
'accent' => ['/^accent
|
|
211
|
+
'accent' => ['/^accent-.+$/'],
|
|
214
212
|
'appearance' => ['/^appearance-(none|auto)$/'],
|
|
215
213
|
'cursor' => ['/^cursor-(auto|default|pointer|wait|text|move|help|not-allowed|none|context-menu|progress|cell|crosshair|vertical-text|alias|copy|no-drop|grab|grabbing|all-scroll|col-resize|row-resize|n-resize|e-resize|s-resize|w-resize|ne-resize|nw-resize|se-resize|sw-resize|ew-resize|ns-resize|nesw-resize|nwse-resize|zoom-in|zoom-out|\[.+\])$/'],
|
|
216
|
-
'caret-color' => ['/^caret
|
|
214
|
+
'caret-color' => ['/^caret-.+$/'],
|
|
217
215
|
'pointer-events' => ['/^pointer-events-(none|auto)$/'],
|
|
218
216
|
'resize' => ['/^resize(-none|-y|-x)?$/'],
|
|
219
217
|
'scroll-behavior' => ['/^scroll-(auto|smooth)$/'],
|
|
@@ -242,6 +240,8 @@ class TwMerge
|
|
|
242
240
|
'mx' => ['mr', 'ml'],
|
|
243
241
|
'my' => ['mt', 'mb'],
|
|
244
242
|
'font-size' => ['line-height'],
|
|
243
|
+
'bg-color' => ['bg-color'],
|
|
244
|
+
'text-color' => ['text-color'],
|
|
245
245
|
'fvn-normal' => ['fvn-ordinal', 'fvn-slashed-zero', 'fvn-figure', 'fvn-spacing', 'fvn-fraction'],
|
|
246
246
|
'rounded' => ['rounded-s', 'rounded-e', 'rounded-t', 'rounded-r', 'rounded-b', 'rounded-l', 'rounded-ss', 'rounded-se', 'rounded-ee', 'rounded-es', 'rounded-tl', 'rounded-tr', 'rounded-br', 'rounded-bl'],
|
|
247
247
|
'rounded-s' => ['rounded-ss', 'rounded-es'],
|
|
@@ -269,12 +269,7 @@ class TwMerge
|
|
|
269
269
|
'scroll-py' => ['scroll-pt', 'scroll-pb'],
|
|
270
270
|
];
|
|
271
271
|
|
|
272
|
-
public static function merge(string ...$inputs): string
|
|
273
|
-
{
|
|
274
|
-
return self::twMerge(...$inputs);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
public static function twMerge(string|array ...$inputs): string
|
|
272
|
+
public static function merge(string|array ...$inputs): string
|
|
278
273
|
{
|
|
279
274
|
$allClasses = [];
|
|
280
275
|
|
|
@@ -292,7 +287,6 @@ class TwMerge
|
|
|
292
287
|
|
|
293
288
|
private static function mergeClassList(array $classes): string
|
|
294
289
|
{
|
|
295
|
-
$classGroupsInConflict = [];
|
|
296
290
|
$result = [];
|
|
297
291
|
|
|
298
292
|
foreach ($classes as $originalClass) {
|
|
@@ -300,96 +294,53 @@ class TwMerge
|
|
|
300
294
|
continue;
|
|
301
295
|
}
|
|
302
296
|
|
|
303
|
-
$
|
|
304
|
-
$modifiers = $modifiersAndClass['modifiers'];
|
|
305
|
-
$baseClass = $modifiersAndClass['baseClass'];
|
|
306
|
-
$hasImportantModifier = $modifiersAndClass['hasImportantModifier'];
|
|
307
|
-
|
|
308
|
-
$classGroup = self::getClassGroup($baseClass);
|
|
309
|
-
if (!$classGroup) {
|
|
310
|
-
$result[] = $originalClass;
|
|
311
|
-
continue;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
$variantModifier = implode(':', $modifiers);
|
|
315
|
-
$modifierId = $hasImportantModifier ? $variantModifier . self::IMPORTANT_MODIFIER : $variantModifier;
|
|
316
|
-
$classGroupId = $modifierId . ':' . $classGroup;
|
|
317
|
-
|
|
318
|
-
$conflictGroups = self::getConflictingClassGroups($classGroup);
|
|
297
|
+
$classKey = self::getClassGroup($originalClass);
|
|
319
298
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
unset($result[array_search($classGroupsInConflict[$groupId], $result)]);
|
|
324
|
-
}
|
|
325
|
-
unset($classGroupsInConflict[$groupId]);
|
|
299
|
+
$conflictingKeys = self::getConflictingKeys($classKey);
|
|
300
|
+
foreach ($conflictingKeys as $key) {
|
|
301
|
+
unset($result[$key]);
|
|
326
302
|
}
|
|
327
303
|
|
|
328
|
-
$
|
|
329
|
-
$result[] = $originalClass;
|
|
304
|
+
$result[$classKey] = $originalClass;
|
|
330
305
|
}
|
|
331
306
|
|
|
332
307
|
return implode(' ', array_values($result));
|
|
333
308
|
}
|
|
334
309
|
|
|
335
|
-
private static function
|
|
336
|
-
{
|
|
337
|
-
$modifiers = [];
|
|
338
|
-
$hasImportantModifier = false;
|
|
339
|
-
$baseClass = $className;
|
|
340
|
-
|
|
341
|
-
if (str_starts_with($className, '!')) {
|
|
342
|
-
$hasImportantModifier = true;
|
|
343
|
-
$baseClass = substr($className, 1);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
$parts = explode(':', $baseClass);
|
|
347
|
-
if (count($parts) > 1) {
|
|
348
|
-
$baseClass = array_pop($parts);
|
|
349
|
-
$modifiers = $parts;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
return [
|
|
353
|
-
'modifiers' => $modifiers,
|
|
354
|
-
'baseClass' => $baseClass,
|
|
355
|
-
'hasImportantModifier' => $hasImportantModifier
|
|
356
|
-
];
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
private static function getClassGroup(string $className): ?string
|
|
310
|
+
private static function getClassGroup(string $class): string
|
|
360
311
|
{
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
if ($pattern
|
|
369
|
-
|
|
312
|
+
$pattern = '/^((?:[^:]+:)*)([^:]+)$/';
|
|
313
|
+
if (preg_match($pattern, $class, $matches)) {
|
|
314
|
+
$prefixes = $matches[1];
|
|
315
|
+
$utilityClass = $matches[2];
|
|
316
|
+
|
|
317
|
+
foreach (self::$classGroups as $groupKey => $patterns) {
|
|
318
|
+
foreach ($patterns as $pattern) {
|
|
319
|
+
if (is_string($pattern) && str_starts_with($pattern, '/')) {
|
|
320
|
+
if (preg_match($pattern, $utilityClass)) {
|
|
321
|
+
return $prefixes . $groupKey;
|
|
322
|
+
}
|
|
323
|
+
} else {
|
|
324
|
+
if ($pattern === $utilityClass) {
|
|
325
|
+
return $prefixes . $groupKey;
|
|
326
|
+
}
|
|
370
327
|
}
|
|
371
328
|
}
|
|
372
329
|
}
|
|
330
|
+
return $prefixes . $utilityClass;
|
|
373
331
|
}
|
|
374
|
-
return
|
|
332
|
+
return $class;
|
|
375
333
|
}
|
|
376
334
|
|
|
377
|
-
private static function
|
|
335
|
+
private static function getConflictingKeys(string $classKey): array
|
|
378
336
|
{
|
|
379
|
-
$
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
$allConflicts = array_merge($allConflicts, $nestedConflicts);
|
|
337
|
+
$baseClassKey = preg_replace("/^(?:[^:]+:)+/", "", $classKey);
|
|
338
|
+
if (isset(self::$conflictingClassGroups[$baseClassKey])) {
|
|
339
|
+
$prefix = preg_replace("/" . preg_quote($baseClassKey, "/") . '$/i', "", $classKey);
|
|
340
|
+
return array_map(function ($conflict) use ($prefix) {
|
|
341
|
+
return $prefix . $conflict;
|
|
342
|
+
}, self::$conflictingClassGroups[$baseClassKey]);
|
|
386
343
|
}
|
|
387
|
-
|
|
388
|
-
return array_unique($allConflicts);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
public static function mergeClasses(string|array ...$classes): string
|
|
392
|
-
{
|
|
393
|
-
return self::twMerge(...$classes);
|
|
344
|
+
return [$classKey];
|
|
394
345
|
}
|
|
395
346
|
}
|
|
@@ -287,12 +287,22 @@ final class Validator
|
|
|
287
287
|
* Validate a JSON string.
|
|
288
288
|
*
|
|
289
289
|
* @param mixed $value The value to validate.
|
|
290
|
-
* @return
|
|
290
|
+
* @return string The JSON string if valid, or throws an exception if invalid.
|
|
291
291
|
*/
|
|
292
|
-
public static function json($value):
|
|
292
|
+
public static function json(mixed $value): string
|
|
293
293
|
{
|
|
294
|
-
|
|
295
|
-
|
|
294
|
+
if (is_string($value)) {
|
|
295
|
+
json_decode($value);
|
|
296
|
+
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
297
|
+
throw new InvalidArgumentException('Invalid JSON string');
|
|
298
|
+
}
|
|
299
|
+
return $value;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return json_encode(
|
|
303
|
+
$value,
|
|
304
|
+
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
|
|
305
|
+
);
|
|
296
306
|
}
|
|
297
307
|
|
|
298
308
|
/**
|