@homebound/truss 2.2.2 → 2.3.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.
- package/build/index.js +12 -9
- package/build/index.js.map +1 -1
- package/build/plugin/index.js +78 -26
- package/build/plugin/index.js.map +1 -1
- package/package.json +1 -1
package/build/plugin/index.js
CHANGED
|
@@ -520,7 +520,8 @@ function getPropertyPriority(property) {
|
|
|
520
520
|
return 3e3;
|
|
521
521
|
}
|
|
522
522
|
function getPseudoClassPriority(pseudo) {
|
|
523
|
-
const
|
|
523
|
+
const leadingPseudo = pseudo.trim().match(/^::?[a-zA-Z-]+/)?.[0] ?? pseudo.split("(")[0];
|
|
524
|
+
const base = leadingPseudo.replace(/[A-Z]/g, function(match) {
|
|
524
525
|
return `-${match.toLowerCase()}`;
|
|
525
526
|
});
|
|
526
527
|
return PSEUDO_CLASS_PRIORITIES[base] ?? 40;
|
|
@@ -587,6 +588,13 @@ var PSEUDO_SUFFIX = {
|
|
|
587
588
|
":active": "_a",
|
|
588
589
|
":disabled": "_d"
|
|
589
590
|
};
|
|
591
|
+
var PSEUDO_SELECTOR_SUFFIX = {
|
|
592
|
+
...PSEUDO_SUFFIX,
|
|
593
|
+
":not": "_n",
|
|
594
|
+
":is": "_is",
|
|
595
|
+
":where": "_where",
|
|
596
|
+
":has": "_has"
|
|
597
|
+
};
|
|
590
598
|
var RELATIONSHIP_SHORT = {
|
|
591
599
|
ancestor: "anc",
|
|
592
600
|
descendant: "desc",
|
|
@@ -604,10 +612,33 @@ function markerClassName(markerNode) {
|
|
|
604
612
|
}
|
|
605
613
|
function whenPrefix(whenPseudo) {
|
|
606
614
|
const rel = RELATIONSHIP_SHORT[whenPseudo.relationship ?? "ancestor"] ?? "anc";
|
|
607
|
-
const pseudoTag =
|
|
615
|
+
const pseudoTag = pseudoSelectorTag(whenPseudo.pseudo);
|
|
608
616
|
const markerPart = whenPseudo.markerNode?.type === "Identifier" ? `${whenPseudo.markerNode.name}_` : "";
|
|
609
617
|
return `wh_${rel}_${pseudoTag}_${markerPart}`;
|
|
610
618
|
}
|
|
619
|
+
function pseudoSelectorTag(pseudo) {
|
|
620
|
+
const replaced = pseudo.trim().replace(/::?[a-zA-Z-]+/g, function(match) {
|
|
621
|
+
return `_${pseudoIdentifierTag(match)}_`;
|
|
622
|
+
});
|
|
623
|
+
const cleaned = replaced.replace(/[^a-zA-Z0-9]/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "");
|
|
624
|
+
return cleaned || "pseudo";
|
|
625
|
+
}
|
|
626
|
+
function pseudoIdentifierTag(pseudo) {
|
|
627
|
+
const normalized = normalizePseudoIdentifier(pseudo);
|
|
628
|
+
const known = PSEUDO_SELECTOR_SUFFIX[normalized];
|
|
629
|
+
if (known) {
|
|
630
|
+
return known.replace(/^_/, "");
|
|
631
|
+
}
|
|
632
|
+
return normalized.replace(/^::?/, "").replace(/-/g, "_");
|
|
633
|
+
}
|
|
634
|
+
function normalizePseudoIdentifier(pseudo) {
|
|
635
|
+
const prefixMatch = pseudo.match(/^::?/);
|
|
636
|
+
const prefix = prefixMatch?.[0] ?? "";
|
|
637
|
+
const name = pseudo.slice(prefix.length).replace(/[A-Z]/g, function(match) {
|
|
638
|
+
return `-${match.toLowerCase()}`;
|
|
639
|
+
});
|
|
640
|
+
return `${prefix}${name}`;
|
|
641
|
+
}
|
|
611
642
|
function conditionPrefix(pseudoClass, mediaQuery, pseudoElement, breakpoints) {
|
|
612
643
|
const parts = [];
|
|
613
644
|
if (pseudoElement) {
|
|
@@ -625,9 +656,7 @@ function conditionPrefix(pseudoClass, mediaQuery, pseudoElement, breakpoints) {
|
|
|
625
656
|
parts.push("mq_");
|
|
626
657
|
}
|
|
627
658
|
if (pseudoClass) {
|
|
628
|
-
|
|
629
|
-
if (tag) parts.push(`${tag.replace(/^_/, "")}_`);
|
|
630
|
-
else parts.push(`${pseudoClass.replace(/^:/, "")}_`);
|
|
659
|
+
parts.push(`${pseudoSelectorTag(pseudoClass)}_`);
|
|
631
660
|
}
|
|
632
661
|
return parts.join("");
|
|
633
662
|
}
|
|
@@ -1234,9 +1263,14 @@ function resolveChain(chain, mapping) {
|
|
|
1234
1263
|
}
|
|
1235
1264
|
if (abbr === "when") {
|
|
1236
1265
|
const resolved = resolveWhenCall(node);
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1266
|
+
if (resolved.kind === "selector") {
|
|
1267
|
+
currentPseudoClass = resolved.pseudo;
|
|
1268
|
+
currentWhenPseudo = null;
|
|
1269
|
+
} else {
|
|
1270
|
+
currentPseudoClass = null;
|
|
1271
|
+
currentMediaQuery = null;
|
|
1272
|
+
currentWhenPseudo = resolved;
|
|
1273
|
+
}
|
|
1240
1274
|
continue;
|
|
1241
1275
|
}
|
|
1242
1276
|
if (isPseudoMethod(abbr)) {
|
|
@@ -1244,7 +1278,7 @@ function resolveChain(chain, mapping) {
|
|
|
1244
1278
|
currentWhenPseudo = null;
|
|
1245
1279
|
if (node.args.length > 0) {
|
|
1246
1280
|
throw new UnsupportedPatternError(
|
|
1247
|
-
`${abbr}() does not take arguments -- use when("ancestor", ":hover") for relationship
|
|
1281
|
+
`${abbr}() does not take arguments -- use when(marker, "ancestor", ":hover") for relationship selectors`
|
|
1248
1282
|
);
|
|
1249
1283
|
}
|
|
1250
1284
|
continue;
|
|
@@ -1544,14 +1578,23 @@ function tryEvaluateAddLiteral(node) {
|
|
|
1544
1578
|
}
|
|
1545
1579
|
var WHEN_RELATIONSHIPS = /* @__PURE__ */ new Set(["ancestor", "descendant", "anySibling", "siblingBefore", "siblingAfter"]);
|
|
1546
1580
|
function resolveWhenCall(node) {
|
|
1547
|
-
if (node.args.length
|
|
1581
|
+
if (node.args.length !== 1 && node.args.length !== 3) {
|
|
1548
1582
|
throw new UnsupportedPatternError(
|
|
1549
|
-
`when() expects
|
|
1583
|
+
`when() expects 1 or 3 arguments (selector) or (marker, relationship, pseudo), got ${node.args.length}`
|
|
1550
1584
|
);
|
|
1551
1585
|
}
|
|
1552
|
-
|
|
1586
|
+
if (node.args.length === 1) {
|
|
1587
|
+
const pseudoArg2 = node.args[0];
|
|
1588
|
+
if (pseudoArg2.type !== "StringLiteral") {
|
|
1589
|
+
throw new UnsupportedPatternError(`when() selector must be a string literal`);
|
|
1590
|
+
}
|
|
1591
|
+
return { kind: "selector", pseudo: pseudoArg2.value };
|
|
1592
|
+
}
|
|
1593
|
+
const markerArg = node.args[0];
|
|
1594
|
+
const markerNode = resolveWhenMarker(markerArg);
|
|
1595
|
+
const relationshipArg = node.args[1];
|
|
1553
1596
|
if (relationshipArg.type !== "StringLiteral") {
|
|
1554
|
-
throw new UnsupportedPatternError(`when()
|
|
1597
|
+
throw new UnsupportedPatternError(`when() relationship argument must be a string literal`);
|
|
1555
1598
|
}
|
|
1556
1599
|
const relationship = relationshipArg.value;
|
|
1557
1600
|
if (!WHEN_RELATIONSHIPS.has(relationship)) {
|
|
@@ -1559,20 +1602,29 @@ function resolveWhenCall(node) {
|
|
|
1559
1602
|
`when() relationship must be one of: ${[...WHEN_RELATIONSHIPS].join(", ")} -- got "${relationship}"`
|
|
1560
1603
|
);
|
|
1561
1604
|
}
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
throw new UnsupportedPatternError(`when() pseudo selector must be a string literal`);
|
|
1566
|
-
}
|
|
1567
|
-
return { pseudo: pseudoArg.value, relationship };
|
|
1568
|
-
} else {
|
|
1569
|
-
const markerNode = node.args[1];
|
|
1570
|
-
const pseudoArg = node.args[2];
|
|
1571
|
-
if (pseudoArg.type !== "StringLiteral") {
|
|
1572
|
-
throw new UnsupportedPatternError(`when() pseudo selector (3rd argument) must be a string literal`);
|
|
1573
|
-
}
|
|
1574
|
-
return { pseudo: pseudoArg.value, markerNode, relationship };
|
|
1605
|
+
const pseudoArg = node.args[2];
|
|
1606
|
+
if (pseudoArg.type !== "StringLiteral") {
|
|
1607
|
+
throw new UnsupportedPatternError(`when() pseudo selector (3rd argument) must be a string literal`);
|
|
1575
1608
|
}
|
|
1609
|
+
return { kind: "relationship", pseudo: pseudoArg.value, markerNode, relationship };
|
|
1610
|
+
}
|
|
1611
|
+
function resolveWhenMarker(node) {
|
|
1612
|
+
if (isDefaultMarkerNode(node)) {
|
|
1613
|
+
return void 0;
|
|
1614
|
+
}
|
|
1615
|
+
if (node.type === "Identifier") {
|
|
1616
|
+
return node;
|
|
1617
|
+
}
|
|
1618
|
+
throw new UnsupportedPatternError(`when() marker must be a marker variable or defaultMarker`);
|
|
1619
|
+
}
|
|
1620
|
+
function isDefaultMarkerNode(node) {
|
|
1621
|
+
if (node.type === "Identifier" && node.name === "defaultMarker") {
|
|
1622
|
+
return true;
|
|
1623
|
+
}
|
|
1624
|
+
return isLegacyDefaultMarkerExpression(node);
|
|
1625
|
+
}
|
|
1626
|
+
function isLegacyDefaultMarkerExpression(node) {
|
|
1627
|
+
return node.type === "CallExpression" && node.arguments.length === 0 && node.callee.type === "MemberExpression" && !node.callee.computed && node.callee.property.type === "Identifier" && node.callee.property.name === "defaultMarker";
|
|
1576
1628
|
}
|
|
1577
1629
|
var PSEUDO_METHODS = {
|
|
1578
1630
|
onHover: ":hover",
|