synthesisui 0.16.123 → 0.16.125
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.
- package/dist/doctor/variant-read.js +38 -1
- package/package.json +1 -1
|
@@ -525,6 +525,36 @@ export function readVariants(source) {
|
|
|
525
525
|
* inline conditions with a class list, 2 of them negated.
|
|
526
526
|
*/
|
|
527
527
|
const INLINE_COND = /(!?)\s*([A-Za-z_$][\w$.]*)\s*(?:===|==)\s*["']([^"']+)["']\s*&&\s*(["'`])((?:(?!\4).)*)\4|(!?)\s*([A-Za-z_$][\w$]*)\s*&&\s*(["'`])((?:(?!\8).)*)\8/g;
|
|
528
|
+
/**
|
|
529
|
+
* THE `cn()` CALL AN OFFSET SITS INSIDE, and its unconditional classes.
|
|
530
|
+
*
|
|
531
|
+
* A condition read out of the whole file has no element: `readInlineConditions(source)`
|
|
532
|
+
* scanned everything and every layer it produced landed on the ROOT. Their collapsible card
|
|
533
|
+
* writes `cursor-pointer` and `hover:bg-…` in the TRIGGER's call and `rotate-180` in the
|
|
534
|
+
* chevron's, and all three arrived as layers of the card - so
|
|
535
|
+
* `.ds-collapsible-card[data-is-open="false"] { transform: rotate(180deg) }` would have
|
|
536
|
+
* turned the whole card upside down at rest (test48, dono, 04/08).
|
|
537
|
+
*
|
|
538
|
+
* The unconditional literals of the enclosing call are exactly what the sketch stored for
|
|
539
|
+
* that node, so `placeLayers` can resolve them to an index. Same identification the lookup
|
|
540
|
+
* reader already uses - see `callSiteClasses`.
|
|
541
|
+
*/
|
|
542
|
+
function enclosingCallClasses(source, at) {
|
|
543
|
+
const CALL = /className=\{\s*(?:[A-Za-z_$][\w$]*\.)?(?:cn|clsx|classNames|cx|twMerge|twJoin|classcat)\(/g;
|
|
544
|
+
CALL.lastIndex = 0;
|
|
545
|
+
let found = null;
|
|
546
|
+
for (const m of source.matchAll(CALL)) {
|
|
547
|
+
const open = (m.index ?? 0) + m[0].length - 1;
|
|
548
|
+
if (open > at)
|
|
549
|
+
break;
|
|
550
|
+
const end = endOf(source, open);
|
|
551
|
+
if (end === -1 || end <= at)
|
|
552
|
+
continue;
|
|
553
|
+
const statics = unconditionalClasses(source.slice(open + 1, end - 1));
|
|
554
|
+
found = statics.length > 0 ? statics.join(" ") : null;
|
|
555
|
+
}
|
|
556
|
+
return found;
|
|
557
|
+
}
|
|
528
558
|
export function readInlineConditions(source) {
|
|
529
559
|
const layers = [];
|
|
530
560
|
INLINE_COND.lastIndex = 0;
|
|
@@ -547,7 +577,14 @@ export function readInlineConditions(source) {
|
|
|
547
577
|
if (classes.length === 0)
|
|
548
578
|
continue;
|
|
549
579
|
const per = splitByCondition(classes, { [prop]: option });
|
|
550
|
-
|
|
580
|
+
/**
|
|
581
|
+
* WHOSE ELEMENT IT IS, off the call this condition sits in. Absent when the call has no
|
|
582
|
+
* unconditional literal to identify it, and then the layer stays on the component -
|
|
583
|
+
* which is the old behaviour, and honest: we could not place it.
|
|
584
|
+
*/
|
|
585
|
+
const on = enclosingCallClasses(source, m.index ?? 0);
|
|
586
|
+
for (const layer of per.layers)
|
|
587
|
+
layers.push(on ? { ...layer, onClasses: on } : layer);
|
|
551
588
|
}
|
|
552
589
|
return layers;
|
|
553
590
|
}
|
package/package.json
CHANGED