@homebound/truss 2.23.0 → 2.24.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.d.ts +18 -6
- package/build/index.js +28 -6
- package/build/index.js.map +1 -1
- package/build/plugin/index.js +36 -13
- package/build/plugin/index.js.map +1 -1
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
package/build/plugin/index.js
CHANGED
|
@@ -1360,6 +1360,21 @@ function normalizePseudoIdentifier(pseudo) {
|
|
|
1360
1360
|
return `${prefix}${name}`;
|
|
1361
1361
|
}
|
|
1362
1362
|
|
|
1363
|
+
// src/spacing-css-var.ts
|
|
1364
|
+
var SPACING_CUSTOM_PROPERTY = "--t-spacing";
|
|
1365
|
+
function incrementCssValue(multiplier) {
|
|
1366
|
+
return `calc(var(${SPACING_CUSTOM_PROPERTY}) * ${multiplier})`;
|
|
1367
|
+
}
|
|
1368
|
+
function tryParseIncrementCalcMultiplier(cssValue) {
|
|
1369
|
+
const prop = SPACING_CUSTOM_PROPERTY.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1370
|
+
const re = new RegExp(`^calc\\(var\\(${prop}\\) \\* (-?\\d+(?:\\.\\d+)?)\\)$`);
|
|
1371
|
+
const m = cssValue.match(re);
|
|
1372
|
+
return m ? m[1] : null;
|
|
1373
|
+
}
|
|
1374
|
+
function rootSpacingPreludeCss(incrementPx) {
|
|
1375
|
+
return `:root { ${SPACING_CUSTOM_PROPERTY}: ${incrementPx}px; }`;
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1363
1378
|
// src/plugin/emit-truss.ts
|
|
1364
1379
|
var RELATIONSHIP_SHORT = {
|
|
1365
1380
|
ancestor: "anc",
|
|
@@ -1413,18 +1428,22 @@ function cleanValueForClassName(value) {
|
|
|
1413
1428
|
}
|
|
1414
1429
|
return cleaned.replace(/[^a-zA-Z0-9]/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "");
|
|
1415
1430
|
}
|
|
1431
|
+
function classNameFragmentForResolvedValue(value) {
|
|
1432
|
+
const inc = tryParseIncrementCalcMultiplier(value);
|
|
1433
|
+
return inc !== null ? cleanValueForClassName(inc) : cleanValueForClassName(value);
|
|
1434
|
+
}
|
|
1416
1435
|
function getPropertyAbbreviation(cssProp) {
|
|
1417
1436
|
return cssPropertyAbbreviations[cssProp] ?? cssProp;
|
|
1418
1437
|
}
|
|
1419
1438
|
function computeStaticBaseName(seg, cssProp, cssValue, isMultiProp, mapping) {
|
|
1420
1439
|
const abbr = seg.abbr;
|
|
1421
1440
|
if (seg.argResolved !== void 0) {
|
|
1422
|
-
const valuePart =
|
|
1441
|
+
const valuePart = classNameFragmentForResolvedValue(seg.argResolved);
|
|
1423
1442
|
if (isMultiProp) {
|
|
1424
1443
|
const lookup = getLonghandLookup(mapping);
|
|
1425
1444
|
const canonical = lookup.get(`${cssProp}\0${cssValue}`);
|
|
1426
1445
|
if (canonical) return canonical;
|
|
1427
|
-
return `${getPropertyAbbreviation(cssProp)}_${
|
|
1446
|
+
return `${getPropertyAbbreviation(cssProp)}_${classNameFragmentForResolvedValue(cssValue)}`;
|
|
1428
1447
|
}
|
|
1429
1448
|
return `${abbr}_${valuePart}`;
|
|
1430
1449
|
}
|
|
@@ -1432,7 +1451,7 @@ function computeStaticBaseName(seg, cssProp, cssValue, isMultiProp, mapping) {
|
|
|
1432
1451
|
const lookup = getLonghandLookup(mapping);
|
|
1433
1452
|
const canonical = lookup.get(`${cssProp}\0${cssValue}`);
|
|
1434
1453
|
if (canonical) return canonical;
|
|
1435
|
-
return `${getPropertyAbbreviation(cssProp)}_${
|
|
1454
|
+
return `${getPropertyAbbreviation(cssProp)}_${classNameFragmentForResolvedValue(cssValue)}`;
|
|
1436
1455
|
}
|
|
1437
1456
|
return abbr;
|
|
1438
1457
|
}
|
|
@@ -1687,16 +1706,17 @@ function toCssVariableName(className, baseKey, cssProp) {
|
|
|
1687
1706
|
const cp = className.endsWith(baseClassName) ? className.slice(0, -baseClassName.length) : "";
|
|
1688
1707
|
return `--${cp}${cssProp}`;
|
|
1689
1708
|
}
|
|
1690
|
-
function buildMaybeIncDeclaration(helperName
|
|
1709
|
+
function buildMaybeIncDeclaration(helperName) {
|
|
1691
1710
|
const incParam = t3.identifier("inc");
|
|
1711
|
+
const calcPrefix = `calc(var(${SPACING_CUSTOM_PROPERTY}) * `;
|
|
1692
1712
|
const body = t3.blockStatement([
|
|
1693
1713
|
t3.returnStatement(
|
|
1694
1714
|
t3.conditionalExpression(
|
|
1695
1715
|
t3.binaryExpression("===", t3.unaryExpression("typeof", incParam), t3.stringLiteral("string")),
|
|
1696
1716
|
incParam,
|
|
1697
1717
|
t3.templateLiteral(
|
|
1698
|
-
[t3.templateElement({ raw:
|
|
1699
|
-
[
|
|
1718
|
+
[t3.templateElement({ raw: calcPrefix, cooked: calcPrefix }, false), t3.templateElement({ raw: ")", cooked: ")" }, true)],
|
|
1719
|
+
[incParam]
|
|
1700
1720
|
)
|
|
1701
1721
|
)
|
|
1702
1722
|
)
|
|
@@ -2320,7 +2340,7 @@ function resolveVariableCall(abbr, entry, node, mapping, mediaQuery, pseudoClass
|
|
|
2320
2340
|
if (node.args.length !== 1) {
|
|
2321
2341
|
throw new UnsupportedPatternError(`${abbr}() expects exactly 1 argument, got ${node.args.length}`);
|
|
2322
2342
|
}
|
|
2323
|
-
const literalValue = tryEvaluateLiteral(node.args[0], entry.incremented
|
|
2343
|
+
const literalValue = tryEvaluateLiteral(node.args[0], entry.incremented);
|
|
2324
2344
|
return buildParameterizedSegment({
|
|
2325
2345
|
abbr,
|
|
2326
2346
|
props: entry.props,
|
|
@@ -2603,10 +2623,10 @@ function isDefaultMarkerNode(node) {
|
|
|
2603
2623
|
function isLegacyDefaultMarkerExpression(node) {
|
|
2604
2624
|
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";
|
|
2605
2625
|
}
|
|
2606
|
-
function tryEvaluateLiteral(node, incremented
|
|
2626
|
+
function tryEvaluateLiteral(node, incremented) {
|
|
2607
2627
|
if (node.type === "NumericLiteral") {
|
|
2608
2628
|
if (incremented) {
|
|
2609
|
-
return
|
|
2629
|
+
return incrementCssValue(node.value);
|
|
2610
2630
|
}
|
|
2611
2631
|
return String(node.value);
|
|
2612
2632
|
}
|
|
@@ -2616,7 +2636,7 @@ function tryEvaluateLiteral(node, incremented, increment) {
|
|
|
2616
2636
|
if (node.type === "UnaryExpression" && node.operator === "-" && node.argument.type === "NumericLiteral") {
|
|
2617
2637
|
const val = -node.argument.value;
|
|
2618
2638
|
if (incremented) {
|
|
2619
|
-
return
|
|
2639
|
+
return incrementCssValue(val);
|
|
2620
2640
|
}
|
|
2621
2641
|
return String(val);
|
|
2622
2642
|
}
|
|
@@ -3729,7 +3749,7 @@ function transformTruss(code, filename, mapping, options = {}) {
|
|
|
3729
3749
|
}
|
|
3730
3750
|
const declarationsToInsert = [];
|
|
3731
3751
|
if (maybeIncHelperName) {
|
|
3732
|
-
declarationsToInsert.push(buildMaybeIncDeclaration(maybeIncHelperName
|
|
3752
|
+
declarationsToInsert.push(buildMaybeIncDeclaration(maybeIncHelperName));
|
|
3733
3753
|
}
|
|
3734
3754
|
for (const [lookupKey, lookup] of runtimeLookups) {
|
|
3735
3755
|
const lookupName = runtimeLookupNames.get(lookupKey);
|
|
@@ -4029,13 +4049,16 @@ function createTrussTransformSession(options) {
|
|
|
4029
4049
|
return result;
|
|
4030
4050
|
}
|
|
4031
4051
|
function collectCss() {
|
|
4052
|
+
const mapping2 = ensureMapping();
|
|
4032
4053
|
const appCssParts = [generateCssText(cssRegistry)];
|
|
4033
4054
|
const allArbitrary = Array.from(arbitraryCssRegistry.values()).join("\n\n");
|
|
4034
4055
|
appCssParts.push(annotateArbitraryCssBlock(allArbitrary));
|
|
4035
4056
|
const appCss = appCssParts.filter((part) => part.length > 0).join("\n");
|
|
4036
4057
|
const libs = loadLibraries();
|
|
4037
|
-
|
|
4038
|
-
|
|
4058
|
+
const body = libs.length === 0 ? appCss : mergeTrussCss([...libs, parseTrussCss(appCss)]);
|
|
4059
|
+
if (body.length === 0) return "";
|
|
4060
|
+
return `${rootSpacingPreludeCss(mapping2.increment)}
|
|
4061
|
+
${body}`;
|
|
4039
4062
|
}
|
|
4040
4063
|
function hasCss() {
|
|
4041
4064
|
return cssRegistry.size > 0 || arbitraryCssRegistry.size > 0 || libraryPaths.length > 0;
|