@homebound/truss 2.2.1 → 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 +85 -42
- 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
|
}
|
|
@@ -812,10 +841,7 @@ function generateCssText(rules) {
|
|
|
812
841
|
for (const rule of allRules) {
|
|
813
842
|
for (const declaration of getRuleDeclarations(rule)) {
|
|
814
843
|
if (declaration.cssVarName) {
|
|
815
|
-
lines.push(`@property ${declaration.cssVarName} {
|
|
816
|
-
syntax: "*";
|
|
817
|
-
inherits: false;
|
|
818
|
-
}`);
|
|
844
|
+
lines.push(`@property ${declaration.cssVarName} { syntax: "*"; inherits: false; }`);
|
|
819
845
|
}
|
|
820
846
|
}
|
|
821
847
|
}
|
|
@@ -880,21 +906,15 @@ function getRuleDeclarations(rule) {
|
|
|
880
906
|
}
|
|
881
907
|
function formatRuleBlock(selector, rule) {
|
|
882
908
|
const body = getRuleDeclarations(rule).map(function(declaration) {
|
|
883
|
-
return
|
|
884
|
-
}).join("
|
|
885
|
-
return `${selector} {
|
|
886
|
-
${body}
|
|
887
|
-
}`;
|
|
909
|
+
return `${declaration.cssProperty}: ${declaration.cssValue};`;
|
|
910
|
+
}).join(" ");
|
|
911
|
+
return `${selector} { ${body} }`;
|
|
888
912
|
}
|
|
889
913
|
function formatNestedRuleBlock(wrapper, selector, rule) {
|
|
890
914
|
const body = getRuleDeclarations(rule).map(function(declaration) {
|
|
891
|
-
return
|
|
892
|
-
}).join("
|
|
893
|
-
return `${wrapper} {
|
|
894
|
-
${selector} {
|
|
895
|
-
${body}
|
|
896
|
-
}
|
|
897
|
-
}`;
|
|
915
|
+
return `${declaration.cssProperty}: ${declaration.cssValue};`;
|
|
916
|
+
}).join(" ");
|
|
917
|
+
return `${wrapper} { ${selector} { ${body} } }`;
|
|
898
918
|
}
|
|
899
919
|
function buildStyleHashProperties(segments, mapping, maybeIncHelperName) {
|
|
900
920
|
const propGroups = /* @__PURE__ */ new Map();
|
|
@@ -1243,9 +1263,14 @@ function resolveChain(chain, mapping) {
|
|
|
1243
1263
|
}
|
|
1244
1264
|
if (abbr === "when") {
|
|
1245
1265
|
const resolved = resolveWhenCall(node);
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1266
|
+
if (resolved.kind === "selector") {
|
|
1267
|
+
currentPseudoClass = resolved.pseudo;
|
|
1268
|
+
currentWhenPseudo = null;
|
|
1269
|
+
} else {
|
|
1270
|
+
currentPseudoClass = null;
|
|
1271
|
+
currentMediaQuery = null;
|
|
1272
|
+
currentWhenPseudo = resolved;
|
|
1273
|
+
}
|
|
1249
1274
|
continue;
|
|
1250
1275
|
}
|
|
1251
1276
|
if (isPseudoMethod(abbr)) {
|
|
@@ -1253,7 +1278,7 @@ function resolveChain(chain, mapping) {
|
|
|
1253
1278
|
currentWhenPseudo = null;
|
|
1254
1279
|
if (node.args.length > 0) {
|
|
1255
1280
|
throw new UnsupportedPatternError(
|
|
1256
|
-
`${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`
|
|
1257
1282
|
);
|
|
1258
1283
|
}
|
|
1259
1284
|
continue;
|
|
@@ -1553,14 +1578,23 @@ function tryEvaluateAddLiteral(node) {
|
|
|
1553
1578
|
}
|
|
1554
1579
|
var WHEN_RELATIONSHIPS = /* @__PURE__ */ new Set(["ancestor", "descendant", "anySibling", "siblingBefore", "siblingAfter"]);
|
|
1555
1580
|
function resolveWhenCall(node) {
|
|
1556
|
-
if (node.args.length
|
|
1581
|
+
if (node.args.length !== 1 && node.args.length !== 3) {
|
|
1557
1582
|
throw new UnsupportedPatternError(
|
|
1558
|
-
`when() expects
|
|
1583
|
+
`when() expects 1 or 3 arguments (selector) or (marker, relationship, pseudo), got ${node.args.length}`
|
|
1559
1584
|
);
|
|
1560
1585
|
}
|
|
1561
|
-
|
|
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];
|
|
1562
1596
|
if (relationshipArg.type !== "StringLiteral") {
|
|
1563
|
-
throw new UnsupportedPatternError(`when()
|
|
1597
|
+
throw new UnsupportedPatternError(`when() relationship argument must be a string literal`);
|
|
1564
1598
|
}
|
|
1565
1599
|
const relationship = relationshipArg.value;
|
|
1566
1600
|
if (!WHEN_RELATIONSHIPS.has(relationship)) {
|
|
@@ -1568,20 +1602,29 @@ function resolveWhenCall(node) {
|
|
|
1568
1602
|
`when() relationship must be one of: ${[...WHEN_RELATIONSHIPS].join(", ")} -- got "${relationship}"`
|
|
1569
1603
|
);
|
|
1570
1604
|
}
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
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`);
|
|
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;
|
|
1584
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";
|
|
1585
1628
|
}
|
|
1586
1629
|
var PSEUDO_METHODS = {
|
|
1587
1630
|
onHover: ":hover",
|