@homebound/truss 2.5.0 → 2.6.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 +1 -0
- package/build/index.js +60 -3
- package/build/index.js.map +1 -1
- package/build/plugin/index.js +29 -29
- package/build/plugin/index.js.map +1 -1
- package/build/toHaveStyle-Y8DGA4JF.d.ts +24 -0
- package/build/vitest.d.ts +13 -0
- package/build/vitest.js +59 -0
- package/build/vitest.js.map +1 -0
- package/package.json +6 -1
- package/tsup.config.ts +1 -0
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -1162,7 +1162,7 @@ export function px(pixels: number): string {
|
|
|
1162
1162
|
}
|
|
1163
1163
|
|
|
1164
1164
|
function omitUndefinedValues<T extends object>(value: T): T {
|
|
1165
|
-
const entries = Object.entries(value).filter(
|
|
1165
|
+
const entries = Object.entries(value).filter(([, entryValue]) => {
|
|
1166
1166
|
return entryValue !== undefined;
|
|
1167
1167
|
});
|
|
1168
1168
|
return Object.fromEntries(entries) as T;
|
|
@@ -1424,7 +1424,7 @@ export function px(pixels: number): string {
|
|
|
1424
1424
|
}
|
|
1425
1425
|
|
|
1426
1426
|
function omitUndefinedValues<T extends object>(value: T): T {
|
|
1427
|
-
const entries = Object.entries(value).filter(
|
|
1427
|
+
const entries = Object.entries(value).filter(([, entryValue]) => {
|
|
1428
1428
|
return entryValue !== undefined;
|
|
1429
1429
|
});
|
|
1430
1430
|
return Object.fromEntries(entries) as T;
|
|
@@ -1547,6 +1547,62 @@ function condensedJson(mapping) {
|
|
|
1547
1547
|
lines.push("}");
|
|
1548
1548
|
return lines.join("\n");
|
|
1549
1549
|
}
|
|
1550
|
+
|
|
1551
|
+
// src/toHaveStyle.ts
|
|
1552
|
+
function toHaveStyle(received, expected) {
|
|
1553
|
+
if (!isElementLike(received)) {
|
|
1554
|
+
return {
|
|
1555
|
+
pass: false,
|
|
1556
|
+
message: () => `expected an Element, received ${printValue(this, "printReceived", received)}`
|
|
1557
|
+
};
|
|
1558
|
+
}
|
|
1559
|
+
const expectedStyles = parseExpectedStyles(received, expected);
|
|
1560
|
+
const mismatches = [];
|
|
1561
|
+
for (const [property, expectedValue] of expectedStyles) {
|
|
1562
|
+
const actualValue = getActualStyleValue(received, property);
|
|
1563
|
+
if (actualValue !== expectedValue) {
|
|
1564
|
+
mismatches.push(`${property}: expected ${expectedValue}, received ${actualValue || "<empty>"}`);
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
return {
|
|
1568
|
+
pass: mismatches.length === 0,
|
|
1569
|
+
message: () => {
|
|
1570
|
+
const expectedLabel = printValue(this, "printExpected", expected);
|
|
1571
|
+
return mismatches.length === 0 ? `expected element not to have style ${expectedLabel}` : `expected element to have style ${expectedLabel}
|
|
1572
|
+
${mismatches.join("\n")}`;
|
|
1573
|
+
}
|
|
1574
|
+
};
|
|
1575
|
+
}
|
|
1576
|
+
function printValue(ctx, kind, value) {
|
|
1577
|
+
return ctx.utils?.[kind]?.(value) ?? JSON.stringify(value);
|
|
1578
|
+
}
|
|
1579
|
+
function isElementLike(value) {
|
|
1580
|
+
return typeof value === "object" && value !== null && "ownerDocument" in value && Boolean(value.ownerDocument?.defaultView);
|
|
1581
|
+
}
|
|
1582
|
+
function toKebabCase(property) {
|
|
1583
|
+
return property.startsWith("--") ? property : property.replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`);
|
|
1584
|
+
}
|
|
1585
|
+
function parseExpectedStyles(el, expected) {
|
|
1586
|
+
const probe = el.ownerDocument.createElement("div");
|
|
1587
|
+
const styles = /* @__PURE__ */ new Map();
|
|
1588
|
+
if (typeof expected === "string") {
|
|
1589
|
+
probe.setAttribute("style", expected);
|
|
1590
|
+
} else {
|
|
1591
|
+
for (const [property, value] of Object.entries(expected)) {
|
|
1592
|
+
probe.style.setProperty(toKebabCase(property), String(value));
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
for (const property of Array.from(probe.style)) {
|
|
1596
|
+
styles.set(property, probe.style.getPropertyValue(property).trim());
|
|
1597
|
+
}
|
|
1598
|
+
return styles;
|
|
1599
|
+
}
|
|
1600
|
+
function getActualStyleValue(el, property) {
|
|
1601
|
+
if (property.startsWith("--")) {
|
|
1602
|
+
return el.style?.getPropertyValue(property).trim() ?? "";
|
|
1603
|
+
}
|
|
1604
|
+
return el.ownerDocument.defaultView.getComputedStyle(el).getPropertyValue(property).trim();
|
|
1605
|
+
}
|
|
1550
1606
|
export {
|
|
1551
1607
|
defaultSections,
|
|
1552
1608
|
defineConfig,
|
|
@@ -1560,6 +1616,7 @@ export {
|
|
|
1560
1616
|
newPxMethod,
|
|
1561
1617
|
newSetCssVariablesMethod,
|
|
1562
1618
|
startStylexCollection,
|
|
1563
|
-
stopStylexCollection
|
|
1619
|
+
stopStylexCollection,
|
|
1620
|
+
toHaveStyle
|
|
1564
1621
|
};
|
|
1565
1622
|
//# sourceMappingURL=index.js.map
|