@homebound/truss 2.21.5 → 2.21.6
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 +21 -49
- package/build/index.js.map +1 -1
- package/build/plugin/index.d.ts +3 -2
- package/build/plugin/index.js +2686 -2732
- package/build/plugin/index.js.map +1 -1
- package/build/runtime.d.ts +4 -1
- package/build/runtime.js +37 -5
- package/build/runtime.js.map +1 -1
- package/package.json +7 -7
- package/tsconfig.tsbuildinfo +1 -0
- package/tsup.config.ts +5 -1
package/build/index.js
CHANGED
|
@@ -922,6 +922,18 @@ var reactNativeSections = {
|
|
|
922
922
|
spacing: spacing2
|
|
923
923
|
};
|
|
924
924
|
|
|
925
|
+
// src/pseudo-selectors.ts
|
|
926
|
+
var TRUSS_PSEUDO_METHODS = {
|
|
927
|
+
onHover: ":hover",
|
|
928
|
+
onFocus: ":focus",
|
|
929
|
+
onFocusVisible: ":focus-visible",
|
|
930
|
+
onFocusWithin: ":focus-within",
|
|
931
|
+
onActive: ":active",
|
|
932
|
+
onDisabled: ":disabled",
|
|
933
|
+
ifFirstOfType: ":first-of-type",
|
|
934
|
+
ifLastOfType: ":last-of-type"
|
|
935
|
+
};
|
|
936
|
+
|
|
925
937
|
// src/generate.ts
|
|
926
938
|
var CssProperties = imp("Properties@csstype");
|
|
927
939
|
var defaultTypeAliases = {
|
|
@@ -1249,6 +1261,12 @@ function generateWebCssBuilder(config, sections) {
|
|
|
1249
1261
|
...Object.entries(genBreakpointsMap).map(([name, value]) => ` ${name} = "${value}",`),
|
|
1250
1262
|
`}`
|
|
1251
1263
|
];
|
|
1264
|
+
const pseudoGetterCode = Object.entries(TRUSS_PSEUDO_METHODS).map(([name, selector]) => {
|
|
1265
|
+
return code`
|
|
1266
|
+
get ${name}() {
|
|
1267
|
+
return this.newCss({ selector: ${quote(selector)} });
|
|
1268
|
+
}`;
|
|
1269
|
+
});
|
|
1252
1270
|
const typographyType = code`
|
|
1253
1271
|
export type ${def("Typography")} = ${Object.keys(fonts).map(quote).join(" | ")};
|
|
1254
1272
|
`;
|
|
@@ -1257,7 +1275,7 @@ function generateWebCssBuilder(config, sections) {
|
|
|
1257
1275
|
// See your project's \`truss-config.ts\` to make configuration changes (fonts, increments, etc).
|
|
1258
1276
|
// Target: web (build-time plugin)
|
|
1259
1277
|
|
|
1260
|
-
import { trussProps, useRuntimeStyle as _useRuntimeStyle } from "@homebound/truss/runtime";
|
|
1278
|
+
import { trussProps, useRuntimeStyle as _useRuntimeStyle, __invertTrussMediaQuery } from "@homebound/truss/runtime";
|
|
1261
1279
|
|
|
1262
1280
|
/** Given a type X, and the user's proposed type T, only allow keys in X and nothing else. */
|
|
1263
1281
|
export type Only<X, T> = X & Record<Exclude<keyof T, keyof X | "__kind">, never>;
|
|
@@ -1335,30 +1353,7 @@ class CssBuilder<T extends Properties, S extends StyleKind = "buildtime"> {
|
|
|
1335
1353
|
return this.rules as any;
|
|
1336
1354
|
}
|
|
1337
1355
|
|
|
1338
|
-
|
|
1339
|
-
return this.newCss({ selector: ":hover" });
|
|
1340
|
-
}
|
|
1341
|
-
get onFocus() {
|
|
1342
|
-
return this.newCss({ selector: ":focus" });
|
|
1343
|
-
}
|
|
1344
|
-
get onFocusVisible() {
|
|
1345
|
-
return this.newCss({ selector: ":focus-visible" });
|
|
1346
|
-
}
|
|
1347
|
-
get onFocusWithin() {
|
|
1348
|
-
return this.newCss({ selector: ":focus-within" });
|
|
1349
|
-
}
|
|
1350
|
-
get onActive() {
|
|
1351
|
-
return this.newCss({ selector: ":active" });
|
|
1352
|
-
}
|
|
1353
|
-
get onDisabled() {
|
|
1354
|
-
return this.newCss({ selector: ":disabled" });
|
|
1355
|
-
}
|
|
1356
|
-
get ifFirstOfType() {
|
|
1357
|
-
return this.newCss({ selector: ":first-of-type" });
|
|
1358
|
-
}
|
|
1359
|
-
get ifLastOfType() {
|
|
1360
|
-
return this.newCss({ selector: ":last-of-type" });
|
|
1361
|
-
}
|
|
1356
|
+
${pseudoGetterCode}
|
|
1362
1357
|
|
|
1363
1358
|
/** Marks this element as a default hover marker (for ancestor pseudo selectors). */
|
|
1364
1359
|
get marker(): CssBuilder<T, S> {
|
|
@@ -1434,7 +1429,7 @@ class CssBuilder<T extends Properties, S extends StyleKind = "buildtime"> {
|
|
|
1434
1429
|
if (this.opts.elseApplied) {
|
|
1435
1430
|
throw new Error("else was already called");
|
|
1436
1431
|
}
|
|
1437
|
-
return this.newCss({ selector:
|
|
1432
|
+
return this.newCss({ selector: __invertTrussMediaQuery(this.selector), elseApplied: true });
|
|
1438
1433
|
}
|
|
1439
1434
|
if (this.opts.elseApplied) {
|
|
1440
1435
|
throw new Error("else was already called");
|
|
@@ -1576,29 +1571,6 @@ ${typeAliasCode}
|
|
|
1576
1571
|
|
|
1577
1572
|
${breakpointCode}
|
|
1578
1573
|
|
|
1579
|
-
function invertMediaQuery(query: string): string {
|
|
1580
|
-
const screenPrefix = "@media screen and ";
|
|
1581
|
-
if (query.startsWith(screenPrefix)) {
|
|
1582
|
-
const conditions = query.slice(screenPrefix.length).trim();
|
|
1583
|
-
const rangeMatch = conditions.match(/^\(min-width: (\d+)px\) and \(max-width: (\d+)px\)$/);
|
|
1584
|
-
if (rangeMatch) {
|
|
1585
|
-
const min = Number(rangeMatch[1]);
|
|
1586
|
-
const max = Number(rangeMatch[2]);
|
|
1587
|
-
return \`@media screen and (max-width: \${min - 1}px), screen and (min-width: \${max + 1}px)\`;
|
|
1588
|
-
}
|
|
1589
|
-
const minMatch = conditions.match(/^\(min-width: (\d+)px\)$/);
|
|
1590
|
-
if (minMatch) {
|
|
1591
|
-
return \`@media screen and (max-width: \${Number(minMatch[1]) - 1}px)\`;
|
|
1592
|
-
}
|
|
1593
|
-
const maxMatch = conditions.match(/^\(max-width: (\d+)px\)$/);
|
|
1594
|
-
if (maxMatch) {
|
|
1595
|
-
return \`@media screen and (min-width: \${Number(maxMatch[1]) + 1}px)\`;
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
return query.replace("@media", "@media not");
|
|
1599
|
-
}
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
1574
|
${extras || ""}
|
|
1603
1575
|
`;
|
|
1604
1576
|
}
|