@homebound/truss 2.15.2 → 2.16.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 +16 -0
- package/build/index.js.map +1 -1
- package/build/plugin/index.js +53 -7
- package/build/plugin/index.js.map +1 -1
- package/build/runtime.d.ts +5 -4
- package/build/runtime.js +24 -6
- package/build/runtime.js.map +1 -1
- package/package.json +1 -1
package/build/plugin/index.js
CHANGED
|
@@ -1115,7 +1115,7 @@ function collectAtomicRules(chains, mapping) {
|
|
|
1115
1115
|
const rules = /* @__PURE__ */ new Map();
|
|
1116
1116
|
let needsMaybeInc = false;
|
|
1117
1117
|
function collectSegment(seg) {
|
|
1118
|
-
if (seg.error || seg.styleArrayArg || seg.classNameArg) return;
|
|
1118
|
+
if (seg.error || seg.styleArrayArg || seg.classNameArg || seg.styleArg) return;
|
|
1119
1119
|
if (seg.typographyLookup) {
|
|
1120
1120
|
for (const segments of Object.values(seg.typographyLookup.segmentsByName)) {
|
|
1121
1121
|
for (const nestedSeg of segments) {
|
|
@@ -1315,7 +1315,7 @@ function buildStyleHashProperties(segments, mapping, maybeIncHelperName) {
|
|
|
1315
1315
|
entries.push(entry);
|
|
1316
1316
|
}
|
|
1317
1317
|
for (const seg of segments) {
|
|
1318
|
-
if (seg.error || seg.styleArrayArg || seg.typographyLookup || seg.classNameArg) continue;
|
|
1318
|
+
if (seg.error || seg.styleArrayArg || seg.typographyLookup || seg.classNameArg || seg.styleArg) continue;
|
|
1319
1319
|
const { prefix } = segmentContext(seg, mapping);
|
|
1320
1320
|
const isConditional = prefix !== "";
|
|
1321
1321
|
if (seg.variableProps) {
|
|
@@ -1718,6 +1718,17 @@ function resolveChain(chain, mapping, initialContext = emptyConditionContext())
|
|
|
1718
1718
|
segments.push(seg);
|
|
1719
1719
|
continue;
|
|
1720
1720
|
}
|
|
1721
|
+
if (abbr === "style") {
|
|
1722
|
+
const seg = resolveStyleCall(
|
|
1723
|
+
node,
|
|
1724
|
+
context.mediaQuery,
|
|
1725
|
+
context.pseudoClass,
|
|
1726
|
+
context.pseudoElement,
|
|
1727
|
+
context.whenPseudo
|
|
1728
|
+
);
|
|
1729
|
+
segments.push(seg);
|
|
1730
|
+
continue;
|
|
1731
|
+
}
|
|
1721
1732
|
if (abbr === "typography") {
|
|
1722
1733
|
const resolved = resolveTypographyCall(
|
|
1723
1734
|
node,
|
|
@@ -1988,6 +1999,25 @@ function resolveClassNameCall(node, mediaQuery, pseudoClass, pseudoElement, when
|
|
|
1988
1999
|
classNameArg: arg
|
|
1989
2000
|
};
|
|
1990
2001
|
}
|
|
2002
|
+
function resolveStyleCall(node, mediaQuery, pseudoClass, pseudoElement, whenPseudo) {
|
|
2003
|
+
if (node.args.length !== 1) {
|
|
2004
|
+
throw new UnsupportedPatternError(`style() expects exactly 1 argument, got ${node.args.length}`);
|
|
2005
|
+
}
|
|
2006
|
+
const arg = node.args[0];
|
|
2007
|
+
if (arg.type === "SpreadElement") {
|
|
2008
|
+
throw new UnsupportedPatternError(`style() does not support spread arguments`);
|
|
2009
|
+
}
|
|
2010
|
+
if (mediaQuery || pseudoClass || pseudoElement || whenPseudo) {
|
|
2011
|
+
throw new UnsupportedPatternError(
|
|
2012
|
+
`style() cannot be used inside media query, pseudo-class, pseudo-element, or when() contexts`
|
|
2013
|
+
);
|
|
2014
|
+
}
|
|
2015
|
+
return {
|
|
2016
|
+
abbr: "style",
|
|
2017
|
+
defs: {},
|
|
2018
|
+
styleArg: arg
|
|
2019
|
+
};
|
|
2020
|
+
}
|
|
1991
2021
|
function resolveAddCall(node, mapping, mediaQuery, pseudoClass, pseudoElement, whenPseudo) {
|
|
1992
2022
|
const isAddCss = node.name === "addCss";
|
|
1993
2023
|
if (isAddCss) {
|
|
@@ -2561,6 +2591,7 @@ function buildStyleHashMembers(segments, options) {
|
|
|
2561
2591
|
const members = [];
|
|
2562
2592
|
const normalSegs = [];
|
|
2563
2593
|
const classNameArgs = [];
|
|
2594
|
+
const styleKeyCounts = /* @__PURE__ */ new Map();
|
|
2564
2595
|
function flushNormal() {
|
|
2565
2596
|
if (normalSegs.length > 0) {
|
|
2566
2597
|
members.push(...buildStyleHashProperties(normalSegs, options.mapping, options.maybeIncHelperName));
|
|
@@ -2573,6 +2604,11 @@ function buildStyleHashMembers(segments, options) {
|
|
|
2573
2604
|
classNameArgs.push(t3.cloneNode(seg.classNameArg, true));
|
|
2574
2605
|
continue;
|
|
2575
2606
|
}
|
|
2607
|
+
if (seg.styleArg) {
|
|
2608
|
+
flushNormal();
|
|
2609
|
+
members.push(buildInlineStyleMember(seg.styleArg, styleKeyCounts));
|
|
2610
|
+
continue;
|
|
2611
|
+
}
|
|
2576
2612
|
if (seg.styleArrayArg) {
|
|
2577
2613
|
flushNormal();
|
|
2578
2614
|
if (seg.isAddCss && t3.isObjectExpression(seg.styleArrayArg)) {
|
|
@@ -2595,7 +2631,7 @@ function buildStyleHashMembers(segments, options) {
|
|
|
2595
2631
|
}
|
|
2596
2632
|
continue;
|
|
2597
2633
|
}
|
|
2598
|
-
if (options.debug && !seg.classNameArg && !seg.styleArrayArg && !seg.typographyLookup) {
|
|
2634
|
+
if (options.debug && !seg.classNameArg && !seg.styleArg && !seg.styleArrayArg && !seg.typographyLookup) {
|
|
2599
2635
|
const isMultiProp = Object.keys(seg.defs).length > 1;
|
|
2600
2636
|
const hasExtraDefs = seg.variableExtraDefs && Object.keys(seg.variableExtraDefs).length > 0;
|
|
2601
2637
|
if (isMultiProp || hasExtraDefs) {
|
|
@@ -2613,14 +2649,21 @@ function buildStyleHashMembers(segments, options) {
|
|
|
2613
2649
|
function buildCustomClassNameMembers(classNameArgs) {
|
|
2614
2650
|
const counts = /* @__PURE__ */ new Map();
|
|
2615
2651
|
return classNameArgs.map((arg) => {
|
|
2616
|
-
const baseKey = `className_${
|
|
2652
|
+
const baseKey = `className_${sanitizeMetadataKey(arg)}`;
|
|
2617
2653
|
const count = (counts.get(baseKey) ?? 0) + 1;
|
|
2618
2654
|
counts.set(baseKey, count);
|
|
2619
2655
|
const key = count === 1 ? baseKey : `${baseKey}_${count}`;
|
|
2620
2656
|
return t3.objectProperty(t3.identifier(key), t3.cloneNode(arg, true));
|
|
2621
2657
|
});
|
|
2622
2658
|
}
|
|
2623
|
-
function
|
|
2659
|
+
function buildInlineStyleMember(arg, counts) {
|
|
2660
|
+
const baseKey = `style_${sanitizeMetadataKey(arg)}`;
|
|
2661
|
+
const count = (counts.get(baseKey) ?? 0) + 1;
|
|
2662
|
+
counts.set(baseKey, count);
|
|
2663
|
+
const key = count === 1 ? baseKey : `${baseKey}_${count}`;
|
|
2664
|
+
return t3.objectProperty(t3.identifier(key), t3.cloneNode(arg, true));
|
|
2665
|
+
}
|
|
2666
|
+
function sanitizeMetadataKey(arg) {
|
|
2624
2667
|
const raw = t3.isStringLiteral(arg) ? arg.value : t3.isTemplateLiteral(arg) && arg.expressions.length === 0 && arg.quasis.length === 1 ? arg.quasis[0].value.cooked ?? "" : generate(arg).code;
|
|
2625
2668
|
const sanitized = raw.replace(/[^a-zA-Z0-9_$]/g, "_").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
|
|
2626
2669
|
return sanitized || "value";
|
|
@@ -2656,7 +2699,7 @@ function buildAddCssObjectMembers(styleObject) {
|
|
|
2656
2699
|
function collectConditionalOnlyProps(segments) {
|
|
2657
2700
|
const allProps = /* @__PURE__ */ new Map();
|
|
2658
2701
|
for (const seg of segments) {
|
|
2659
|
-
if (seg.error || seg.styleArrayArg || seg.typographyLookup || seg.classNameArg) continue;
|
|
2702
|
+
if (seg.error || seg.styleArrayArg || seg.typographyLookup || seg.classNameArg || seg.styleArg) continue;
|
|
2660
2703
|
const hasCondition = !!(seg.pseudoClass || seg.mediaQuery || seg.pseudoElement || seg.whenPseudo);
|
|
2661
2704
|
const props = seg.variableProps ?? Object.keys(seg.defs);
|
|
2662
2705
|
for (const prop of props) {
|
|
@@ -2750,7 +2793,7 @@ function clonePropertyKey(key) {
|
|
|
2750
2793
|
function injectDebugInfo(expr, line, options) {
|
|
2751
2794
|
if (!options.debug) return;
|
|
2752
2795
|
const firstProp = expr.properties.find((p) => {
|
|
2753
|
-
return t3.isObjectProperty(p) && !(t3.isIdentifier(p.key) && p.key.name.startsWith("className_") || t3.isStringLiteral(p.key) && p.key.value.startsWith("className_") || t3.isIdentifier(p.key) && p.key.name === "__marker" || t3.isStringLiteral(p.key) && p.key.value === "__marker");
|
|
2796
|
+
return t3.isObjectProperty(p) && !(t3.isIdentifier(p.key) && p.key.name.startsWith("className_") || t3.isStringLiteral(p.key) && p.key.value.startsWith("className_") || t3.isIdentifier(p.key) && p.key.name.startsWith("style_") || t3.isStringLiteral(p.key) && p.key.value.startsWith("style_") || t3.isIdentifier(p.key) && p.key.name === "__marker" || t3.isStringLiteral(p.key) && p.key.value === "__marker");
|
|
2754
2797
|
});
|
|
2755
2798
|
if (!firstProp) return;
|
|
2756
2799
|
options.needsTrussDebugInfo.current = true;
|
|
@@ -3313,6 +3356,9 @@ function resolveCssExpression(node, cssBindingName, mapping, filename) {
|
|
|
3313
3356
|
if (seg.styleArrayArg) {
|
|
3314
3357
|
return { error: `add(cssProp) is not supported in .css.ts files` };
|
|
3315
3358
|
}
|
|
3359
|
+
if (seg.styleArg) {
|
|
3360
|
+
return { error: `style() is not supported in .css.ts files` };
|
|
3361
|
+
}
|
|
3316
3362
|
if (seg.mediaQuery) {
|
|
3317
3363
|
return { error: `media query modifiers (ifSm, ifMd, etc.) are not supported in .css.ts files` };
|
|
3318
3364
|
}
|