Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
-
CI results over the last 21 days
- Manifest: layout/inspector/tests/mochitest.toml
<!DOCTYPE HTML>
<html>
<head>
<title>Test InspectorUtils.getComputationSteps</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<code>InspectorUtils.getComputationSteps</code>
<style>
* {
box-sizing: border-box;
}
:root {
font-size: 20px;
line-height: 24px;
}
main {
--on-main: 2em;
--registered: 3em;
--registered-inherits: 4em;
--ten-percent: 10%;
container-type: size;
width: 200px;
height: 100px;
}
section {
--on-section: 1em;
--space-separated-lengths: calc(1px + 1em) calc(-1 * 2cqb) 3rem clamp(30px, calc(4lh + 1em), 100cqw);
--shadow-parts: -0.2em 10px 8cqi /* color */ hotpink, 1rem 1lh 1cqmax rgb(255, 215, 0);
width: 100px;
height: 50px;
font-size: 24px;
line-height: 28px;
&::after {
font-size: 28px;
}
}
li {
width: 120px;
height: 30px;
box-decoration-break: clone;
}
.indefinite-block-size {
width: 200px;
/* no explicit height, so block-size is indefinite */
}
.indefinite-block-size > div {
width: 100px;
position: relative;
}
#zero-height-absolute-child, #non-zero-height-absolute-child {
position: absolute;
}
#child-of-non-zero-indefinite-block-size > aside {
height: 80px;
}
@property --registered {
syntax: "<length>";
inherits: false;
initial-value: 123px;
}
@property --registered-inherits {
syntax: "<length>";
inherits: true;
initial-value: 123px;
}
</style>
<main>
<section data-x="10" data-y="tomato">Section.80</section>
<ol>
<li>First</li>
<li>Second</li>
<li>Third</li>
</ol>
</main>
<div class="indefinite-block-size">
<div id="child-of-indefinite-block-size">
<div id="zero-height-absolute-child"></div>
</div>
</div>
<div class="indefinite-block-size">
<div id="child-of-non-zero-indefinite-block-size">
<div id="non-zero-height-absolute-child"></div>
<aside>fries</aside>
</div>
</div>
<script>
add_task(async function() {
const { InspectorUtils } = SpecialPowers;
const test = ({expression, el, property = "", pseudo, expected }) => {
const res = Array.from(InspectorUtils.getComputationSteps(property, expression, el, pseudo));
const outer = el.outerHTML;
const fmt = arr => `(${arr.length})[${arr.map(s => `'${s}'`).join(", ")}]`
is(
fmt(res),
fmt(expected),
`Got expected steps for "${expression}" on ${outer.substring(0, outer.indexOf(">") + 1)}${pseudo ? "::" + pseudo: ""}${property ? ` for the "${property}" property`: ""}`
);
}
const sectionEl = document.querySelector("section");
const firstLiEl = document.querySelector("li");
const childOfIndefiniteBlockSize = document.getElementById("child-of-indefinite-block-size");
const zeroHeightAbsoluteChild = document.getElementById("zero-height-absolute-child");
const nonZeroHeightAbsoluteChild = document.getElementById("non-zero-height-absolute-child");
/// clamp()
test({
expression: "clamp(1,2,3)",
el: sectionEl,
expected: [
"clamp(1, 2, 3)",
"2"
]
});
test({
expression: "clamp(3,2,1)",
el: sectionEl,
expected: [
"clamp(3, 2, 1)",
"3"
]
});
test({
expression: "clamp(1,3,2)",
el: sectionEl,
expected: [
"clamp(1, 3, 2)",
"2"
]
});
/// round()
test({
expression: "round(10.5)",
el: sectionEl,
expected: [
"round(10.5)",
"round(10.5, 1)",
"11"
]
});
test({
expression: "round(10.5,1)",
el: sectionEl,
expected: [
"round(10.5, 1)",
"11"
]
});
test({
expression: "round(Infinity)",
el: sectionEl,
expected: [
"round(Infinity)",
"round(infinity, 1)",
"infinity"
]
});
test({
expression: "round(10.5, 2)",
el: sectionEl,
expected: [
"round(10.5, 2)",
"10"
]
});
test({
expression: "round(up, 10.5)",
el: sectionEl,
expected: [
"round(up, 10.5)",
"round(up, 10.5, 1)",
"11"
]
});
test({
expression: "round(down, 10.5)",
el: sectionEl,
expected: [
"round(down, 10.5)",
"round(down, 10.5, 1)",
"10"
]
});
test({
expression: "round(nearest, 10.5)",
el: sectionEl,
expected: [
"round(nearest, 10.5)",
"round(10.5, 1)",
"11"
]
});
test({
expression: "round(to-zero, 10.5)",
el: sectionEl,
expected: [
"round(to-zero, 10.5)",
"round(to-zero, 10.5, 1)",
"10"
]
});
test({
expression: "round(up, Infinity)",
el: sectionEl,
expected: [
"round(up, Infinity)",
"round(up, infinity, 1)",
"infinity"
]
});
test({
expression: "round(up, 10.5, Infinity)",
el: sectionEl,
expected: [
"round(up, 10.5, infinity)",
"infinity"
]
});
test({
expression: "round(down, 10.5, Infinity)",
el: sectionEl,
expected: [
"round(down, 10.5, infinity)",
"0"
]
});
test({
expression: "round(nearest, 10.5, Infinity)",
el: sectionEl,
expected: [
"round(nearest, 10.5, Infinity)",
"round(10.5, infinity)",
"0"
]
});
test({
expression: "round(to-zero, 10.5, Infinity)",
el: sectionEl,
expected: [
"round(to-zero, 10.5, infinity)",
"0"
]
});
test({
expression: "round(up, -10.5, Infinity)",
el: sectionEl,
expected: [
"round(up, -10.5, infinity)",
"0"
]
});
test({
expression: "round(down, -10.5, Infinity)",
el: sectionEl,
expected: [
"round(down, -10.5, infinity)",
"-infinity"
]
});
test({
expression: "round(nearest, -10.5, Infinity)",
el: sectionEl,
expected: [
"round(nearest, -10.5, Infinity)",
"round(-10.5, infinity)",
"0"
]
});
test({
expression: "round(to-zero, -10.5, Infinity)",
el: sectionEl,
expected: [
"round(to-zero, -10.5, infinity)",
"0"
]
});
test({
expression: "round(up, -10.5)",
el: sectionEl,
expected: [
"round(up, -10.5)",
"round(up, -10.5, 1)",
"-10"
]
});
test({
expression: "round(down, -10.5)",
el: sectionEl,
expected: [
"round(down, -10.5)",
"round(down, -10.5, 1)",
"-11"
]
});
test({
expression: "round(nearest, -10.5)",
el: sectionEl,
expected: [
"round(nearest, -10.5)",
"round(-10.5, 1)",
"-10"
]
});
test({
expression: "round(to-zero, -10.5)",
el: sectionEl,
expected: [
"round(to-zero, -10.5)",
"round(to-zero, -10.5, 1)",
"-10"
]
});
test({
expression: "round(up, 0, -1)",
el: sectionEl,
expected: [
"round(up, 0, -1)",
"0"
]
});
test({
expression: "round(down, 0, -1)",
el: sectionEl,
expected: [
"round(down, 0, -1)",
"0"
]
});
test({
expression: "round(nearest, 0, -1)",
el: sectionEl,
expected: [
"round(nearest, 0, -1)",
"round(0, -1)",
"0"
]
});
test({
expression: "round(to-zero, 0, -1)",
el: sectionEl,
expected: [
"round(to-zero, 0, -1)",
"0"
]
});
/// mod()
test({
expression: "mod(3.5, 2)",
el: sectionEl,
expected: [
"mod(3.5, 2)",
"1.5",
]
});
/// rem()
test({
expression: "rem(3.5, 2)",
el: sectionEl,
expected: [
"rem(3.5, 2)",
"1.5",
]
});
/// sin()
test({
expression: "sin(0deg)",
el: sectionEl,
expected: [
"sin(0deg)",
"0",
]
});
/// cos()
test({
expression: "cos(pi)",
el: sectionEl,
expected: [
"cos(pi)",
"cos(3.14159)",
"-1",
]
});
/// tan()
test({
expression: "tan(0.125turn)",
el: sectionEl,
expected: [
"tan(0.125turn)",
"1",
]
});
/// asin()
test({
expression: "asin(0.5)",
el: sectionEl,
expected: [
"asin(0.5)",
"30deg",
]
});
test({
expression: "asin(2)",
el: sectionEl,
expected: [
"asin(2)",
"NaN * 1deg",
]
});
/// acos()
test({
expression: "acos(0.5)",
el: sectionEl,
expected: [
"acos(0.5)",
"60deg",
]
});
test({
expression: "acos(2)",
el: sectionEl,
expected: [
"acos(2)",
"NaN * 1deg",
]
});
/// atan()
test({
expression: "atan(-1)",
el: sectionEl,
expected: [
"atan(-1)",
"-45deg",
]
});
test({
expression: "atan(Infinity)",
el: sectionEl,
expected: [
"atan(infinity)",
"90deg",
]
});
/// atan2()
test({
expression: "atan2(1rem, -0.5rem)",
el: sectionEl,
expected: [
"atan2(1rem, -0.5rem)",
"atan2(20px, -10px)",
"116.565deg",
]
});
/// pow()
test({
expression: "pow(5, 2)",
el: sectionEl,
expected: [
"pow(5, 2)",
"25",
]
});
/// sqrt()
test({
expression: "sqrt(9)",
el: sectionEl,
expected: [
"sqrt(9)",
"3",
]
});
/// hypot()
test({
expression: "hypot(2em)",
el: sectionEl,
expected: [
"hypot(2em)",
"hypot(48px)",
"48px",
]
});
test({
expression: "hypot(4em, 3em)",
el: sectionEl,
expected: [
"hypot(4em, 3em)",
"hypot(96px, 72px)",
"120px",
]
});
/// log()
test({
expression: "log(1)",
el: sectionEl,
expected: [
"log(1)",
"0",
]
});
test({
expression: "log(8, 2)",
el: sectionEl,
expected: [
"log(8, 2)",
"3",
]
});
/// exp()
test({
expression: "exp(1)",
el: sectionEl,
expected: [
"exp(1)",
"2.71828",
]
});
/// abs()
test({
expression: "abs(-1em)",
el: sectionEl,
expected: [
"abs(-1em)",
"abs(-24px)",
"24px",
]
});
/// sign()
test({
expression: "sign(-1em)",
el: sectionEl,
expected: [
"sign(-1em)",
"sign(-24px)",
"-1",
]
});
/// min()
test({
expression: "min(1em, 10cqh)",
el: sectionEl,
expected: [
"min(1em, 10cqh)",
"min(24px, 10px)",
"10px",
]
});
test({
expression: "min(acos(2), 90deg)",
el: sectionEl,
expected: [
"min(acos(2), 90deg)",
"min(NaN * 1deg, 90deg)",
"NaN * 1deg",
]
});
/// max()
test({
expression: "max(1em, 10cqh)",
el: sectionEl,
expected: [
"max(1em, 10cqh)",
"max(24px, 10px)",
"24px",
]
});
test({
expression: "max(acos(2), 90deg)",
el: sectionEl,
expected: [
"max(acos(2), 90deg)",
"max(NaN * 1deg, 90deg)",
"NaN * 1deg",
]
});
/// sibling-index()
test({
expression: "sibling-index()",
el: document.querySelector("li:nth-of-type(1)"),
expected: [
"sibling-index()",
"1",
]
});
test({
expression: "sibling-index()",
el: document.querySelector("li:nth-of-type(2)"),
expected: [
"sibling-index()",
"2",
]
});
test({
expression: "sibling-index()",
el: document.querySelector("li:nth-of-type(2)"),
pseudo: "::marker",
expected: [
"sibling-index()",
"2",
]
});
/// sibling-count()
test({
expression: "sibling-count()",
el: document.querySelector("li:nth-of-type(1)"),
expected: [
"sibling-count()",
"3",
]
});
test({
expression: "sibling-count()",
el: document.querySelector("li:nth-of-type(2)"),
expected: [
"sibling-count()",
"3",
]
});
test({
expression: "sibling-count()",
el: document.querySelector("li:nth-of-type(2)"),
pseudo: "::marker",
expected: [
"sibling-count()",
"3",
]
});
/// progress()
test({
expression: "progress(5, 0, 10)",
el: sectionEl,
expected: [
"progress(5, 0, 10)",
"0.5",
]
});
test({
expression: "progress(2em, 2cqw, 92cqh)",
el: sectionEl,
expected: [
"progress(2em, 2cqw, 92cqh)",
"progress(48px, 4px, 92px)",
"0.5",
]
});
test({
expression: "progress(2em, 0cqw, 2.4cqw)",
el: sectionEl,
expected: [
"progress(2em, 0cqw, 2.4cqw)",
"progress(48px, 0px, 4.8px)",
"1",
]
});
test({
expression: "progress(no-clamp 2em, 0cqw, 2.4cqw)",
el: sectionEl,
expected: [
"progress(no-clamp 2em, 0cqw, 2.4cqw)",
"progress(no-clamp 48px, 0px, 4.8px)",
"10",
]
});
/// var()
test({
expression: "var(--on-section)",
el: sectionEl,
expected: [
"var(--on-section)",
"1em",
"24px",
]
});
test({
expression: "var(--on-section, Infinity)",
el: sectionEl,
expected: [
"var(--on-section, Infinity)",
"1em",
"24px",
]
});
test({
expression: "var(--on-main)",
el: sectionEl,
expected: [
"var(--on-main)",
"2em",
"48px",
]
});
test({
expression: "var(--on-main, Infinity)",
el: sectionEl,
expected: [
"var(--on-main, Infinity)",
"2em",
"48px",
]
});
test({
expression: "var(--undef)",
el: sectionEl,
// Undefined variable can't be substituted
// XXX Ideally, we'd show a meaningful message for this
expected: []
});
test({
expression: "var(--undef, Infinity)",
el: sectionEl,
expected: [
"var(--undef, Infinity)",
"Infinity"
]
});
test({
expression: "var(--undef, var(--on-section))",
el: sectionEl,
expected: [
"var(--undef, var(--on-section))",
"1em",
"24px",
]
});
test({
expression: "var(--registered)",
el: sectionEl,
expected: [
"var(--registered)",
// --registered does not inherit and is not set on section, we should get the initial value
"123px"
]
});
test({
expression: "var(--registered-inherits)",
el: sectionEl,
expected: [
"var(--registered-inherits)",
// --registered-inherits is not set on section, but it is on main, and it does inherit
// so we should get the value set on main: 4em -> 4 * 20px -> 80px.
// XXX It would be nice to get the computation detail here too
"80px"
]
});
test({
property: "margin",
expression: "var(--space-separated-lengths)",
el: sectionEl,
expected: [
"var(--space-separated-lengths)",
"calc(1px + 1em) calc(-1 * 2cqb) 3rem clamp(30px, calc(4lh + 1em), 100cqw)",
"calc(1px + 24px) calc(-1 * 2cqb) 3rem clamp(30px, 4lh + 1em, 100cqw)",
"25px calc(-1 * 2cqb) 3rem clamp(30px, 4lh + 1em, 100cqw)",
"25px calc(-1 * 2px) 3rem clamp(30px, 4lh + 1em, 100cqw)",
"25px -2px 3rem clamp(30px, 4lh + 1em, 100cqw)",
"25px -2px 60px clamp(30px, 4lh + 1em, 100cqw)",
"25px -2px 60px clamp(30px, 112px + 24px, 200px)",
"25px -2px 60px clamp(30px, 136px, 200px)",
"25px -2px 60px 136px",
]
});
test({
property: "margin",
expression: "4em 3cqb 2rem 1lh",
el: sectionEl,
expected: [
"4em 3cqb 2rem 1lh",
"96px 3cqb 2rem 1lh",
"96px 3px 2rem 1lh",
"96px 3px 40px 1lh",
"96px 3px 40px 28px",
]
});
test({
property: "box-shadow",
expression: "var(--shadow-parts)",
el: sectionEl,
expected: [
"var(--shadow-parts)",
"-0.2em 10px 8cqi /* color */ hotpink, 1rem 1lh 1cqmax rgb(255, 215, 0)",
"-4.8px 10px 8cqi hotpink, 1rem 1lh 1cqmax rgb(255, 215, 0)",
"-4.8px 10px 16px hotpink, 1rem 1lh 1cqmax rgb(255, 215, 0)",
"-4.8px 10px 16px hotpink, 20px 1lh 1cqmax rgb(255, 215, 0)",
"-4.8px 10px 16px hotpink, 20px 28px 1cqmax rgb(255, 215, 0)",
"-4.8px 10px 16px hotpink, 20px 28px 2px rgb(255, 215, 0)",
]
});
test({
property: "box-shadow",
expression: "0.2em 20px 4cqi tomato, 1rem 1lh 1cqmax gold",
el: sectionEl,
expected: [
"0.2em 20px 4cqi tomato, 1rem 1lh 1cqmax gold",
"4.8px 20px 4cqi tomato, 1rem 1lh 1cqmax gold",
"4.8px 20px 8px tomato, 1rem 1lh 1cqmax gold",
"4.8px 20px 8px tomato, 20px 1lh 1cqmax gold",
"4.8px 20px 8px tomato, 20px 28px 1cqmax gold",
"4.8px 20px 8px tomato, 20px 28px 2px gold",
]
});
/// attr()
test({
expression: "attr(data-x)",
el: sectionEl,
expected: [
"attr(data-x)",
`"10"`
]
});
test({
expression: "attr(data-x px)",
el: sectionEl,
expected: [
"attr(data-x px)",
"10px"
]
});
test({
expression: "attr(data-x type(<number>))",
el: sectionEl,
expected: [
"attr(data-x type(<number>))",
"10"
]
});
test({
expression: "attr(data-x type(<color>))",
el: sectionEl,
// XXX: attribute value ("10") doesn't match what's expected from type(<color>)
// Ideally, we'd show a meaningful message for this
expected: []
});
test({
expression: "attr(data-y type(<color>))",
el: sectionEl,
expected: [
"attr(data-y type(<color>))",
"tomato"
]
});
test({
expression: "attr(data-x px, Infinity)",
el: sectionEl,
expected: [
"attr(data-x px, Infinity)",
"10px"
]
});
test({
expression: "attr(data-undef)",
el: sectionEl,
// Undefined attribute can't be substituted
// XXX Ideally, we'd show a meaningful message for this
expected: [
"attr(data-undef)",
`""`
]
});
test({
expression: `attr(data-undef, "hello")`,
el: sectionEl,
expected: [
`attr(data-undef, "hello")`,
`"hello"`
]
});
test({
expression: "attr(data-undef px)",
el: sectionEl,
// Undefined attribute can't be substituted
// XXX Ideally, we'd show a meaningful message for this
expected: []
});
test({
expression: "attr(data-undef px, Infinity)",
el: sectionEl,
expected: [
"attr(data-undef px, Infinity)",
"Infinity"
]
});
test({
expression: "attr(data-undef px, attr(data-x px, Infinity))",
el: sectionEl,
expected: [
"attr(data-undef px, attr(data-x px, Infinity))",
"10px"
]
});
/// env()
test({
expression: "env(safe-area-inset-top)",
el: sectionEl,
expected: [
"env(safe-area-inset-top)",
"0.0px"
]
});
test({
expression: "env(safe-area-inset-top, 10px)",
el: sectionEl,
expected: [
"env(safe-area-inset-top, 10px)",
"0.0px"
]
});
test({
expression: "env(undef)",
el: sectionEl,
expected: [
]
});
test({
expression: "env(undef, 10px)",
el: sectionEl,
expected: [
"env(undef, 10px)",
"10px",
]
});
/// random-item()
test({
expression: "random-item(auto, 1px)",
el: sectionEl,
property: "width",
expected: ["random-item(auto, 1px)", "1px"]
});
test({
expression: "random-item(property-scoped, 1px)",
el: sectionEl,
property: "width",
expected: ["random-item(property-scoped, 1px)", "1px"]
});
test({
expression: "random-item(element-scoped, 1px)",
el: sectionEl,
property: "width",
expected: ["random-item(element-scoped, 1px)", "1px"]
});
test({
expression: "random-item(--key, 1px)",
el: sectionEl,
property: "width",
expected: ["random-item(--key, 1px)", "1px"]
});
test({
expression: "random-item(fixed 0.5, 1px)",
el: sectionEl,
property: "width",
expected: ["random-item(fixed 0.5, 1px)", "1px"]
});
test({
expression: "random-item(auto, 10em)",
el: sectionEl,
property: "width",
expected: ["random-item(auto, 10em)", "10em", "240px"]
});
/// calc() operations
test({
expression: "calc(1px)",
el: sectionEl,
expected: ["calc(1px)", "1px"]
});
test({
expression: "calc(1px + 2px)",
el: sectionEl,
expected: [
"calc(1px + 2px)",
"3px"
]
});
test({
expression: "calc(1px - 2px)",
el: sectionEl,
expected: [
"calc(1px - 2px)",
"-1px"
]
});
test({
expression: "calc(1px * 2)",
el: sectionEl,
expected: [
"calc(1px * 2)",
"2px"
]
});
test({
expression: "calc(1px / 2)",
el: sectionEl,
expected: [
"calc(1px / 2)",
"calc(1px * 0.5)",
"0.5px",
]
});
/// Complex expressions
test({
expression: "calc(10cqw + 20cqh + 30px)",
el: sectionEl,
expected: [
"calc(10cqw + 20cqh + 30px)",
"calc(20px + 20px + 30px)",
"70px",
]
});
test({
expression: "min(1em, 10cqw)",
el: sectionEl,
expected: [
"min(1em, 10cqw)",
"min(24px, 20px)",
"20px",
]
});
test({
expression: "calc(min(sin(pi * 1.5), cos(0rad)) * 2px)",
el: sectionEl,
expected: [
"calc(min(sin(pi * 1.5), cos(0rad)) * 2px)",
"calc(min(sin(3.14159 * 1.5), cos(0rad)) * 2px)",
"calc(min(sin(4.71239), cos(0rad)) * 2px)",
"calc(min(-1, cos(0rad)) * 2px)",
"calc(min(-1, 1) * 2px)",
"calc(-1 * 2px)",
"-2px",
]
});
test({
expression: "clamp(10cqmax, 3em, 15cqw)",
el: sectionEl,
expected: [
"clamp(10cqmax, 3em, 15cqw)",
"clamp(20px, 72px, 30px)",
"30px",
]
});
test({
expression: "clamp(5cqmin, 3em, min(10cqw, 30cqh))",
el: sectionEl,
expected: [
"clamp(5cqmin, 3em, min(10cqw, 30cqh))",
"clamp(5px, 72px, min(20px, 30px))",
"clamp(5px, 72px, 20px)",
"20px",
]
});
test({
property: "width",
expression: "clamp(5%, 3em, 10cqw)",
el: sectionEl,
expected: [
"clamp(5%, 3em, 10cqw)",
"clamp(10px, 72px, 20px)",
"20px",
]
});
test({
property: "height",
expression: "clamp(5%, 3em, 10cqw)",
el: sectionEl,
expected: [
"clamp(5%, 3em, 10cqw)",
"clamp(5px, 72px, 20px)",
"20px",
]
});
test({
property: "height",
expression: "calc(0% + 10cqh)",
el: sectionEl,
expected: [
"calc(0% + 10cqh)",
"calc(0px + 10px)",
"10px",
]
});
test({
expression: "min(sin(90deg), cos(min(0, max(0, Infinity))))",
el: sectionEl,
expected: [
"min(sin(90deg), cos(min(0, max(0, infinity))))",
"min(1, cos(min(0, max(0, infinity))))",
"min(1, cos(min(0, infinity)))",
"min(1, cos(0))",
"min(1, 1)",
"1",
]
});
test({
expression: "max(42, Infinity)",
el: sectionEl,
expected: [
// TODO: Check if it should be Infinity (with uppercase I)
"max(42, infinity)",
"infinity",
]
});
test({
expression: "mod(mod(mod(3.5, 2), 3), 42)",
el: sectionEl,
expected: [
"mod(mod(mod(3.5, 2), 3), 42)",
"mod(mod(1.5, 3), 42)",
"mod(1.5, 42)",
"1.5",
]
});
test({
expression: "abs(sin(270deg))",
el: sectionEl,
expected: [
"abs(sin(270deg))",
"abs(-1)",
"1",
]
});
test({
expression: "calc(10cqw + 20cqh + 30px + (min(cos(pi) * abs(-4), mod(10, 23))) * 1cqmin)",
el: sectionEl,
expected: [
"calc(10cqw + 20cqh + 30px + (min(cos(pi) * abs(-4), mod(10, 23))) * 1cqmin)",
"calc(10cqw + 20cqh + 30px + (min(cos(3.14159) * abs(-4), mod(10, 23)) * 1cqmin))",
"calc(20px + 20px + 30px + (min(cos(3.14159) * abs(-4), mod(10, 23)) * 1px))",
"calc(20px + 20px + 30px + (min(-1 * abs(-4), mod(10, 23)) * 1px))",
"calc(20px + 20px + 30px + (min(-1 * 4, mod(10, 23)) * 1px))",
"calc(20px + 20px + 30px + (min(-4, mod(10, 23)) * 1px))",
"calc(20px + 20px + 30px + (min(-4, 10) * 1px))",
"calc(20px + 20px + 30px + (-4 * 1px))",
"calc(20px + 20px + 30px - 4px)",
"66px",
]
});
test({
expression: "min(cos(2 * pi) * abs(-4), mod(10, 23))",
el: sectionEl,
expected: [
"min(cos(2 * pi) * abs(-4), mod(10, 23))",
"min(cos(2 * 3.14159) * abs(-4), mod(10, 23))",
"min(cos(6.28319) * abs(-4), mod(10, 23))",
"min(1 * abs(-4), mod(10, 23))",
"min(1 * 4, mod(10, 23))",
"min(4, mod(10, 23))",
"min(4, 10)",
"4",
]
});
test({
expression: "calc((3em + 4rem) / 2)",
el: sectionEl,
expected: [
"calc((3em + 4rem) / 2)",
"calc((72px + 80px) / 2)",
"calc(152px / 2)",
"calc(152px * 0.5)",
"76px",
]
});
test({
expression: "calc((3em + 4rem) / (10 * 5em))",
el: sectionEl,
expected: [
"calc((3em + 4rem) / (10 * 5em))",
"calc((72px + 80px) / (10 * 120px))",
"calc(152px / (10 * 120px))",
"calc(152px / 1200px)",
"0.126667",
]
});
test({
expression: "calc((3em + 4rem) / 2)",
el: sectionEl,
pseudo: "::after",
expected: [
"calc((3em + 4rem) / 2)",
"calc((84px + 80px) / 2)",
"calc(164px / 2)",
"calc(164px * 0.5)",
"82px",
]
});
test({
expression: "calc((1em * max(sibling-index(), 10)) + (min(2, sibling-count()) * 0.5rem))",
el: document.querySelector("li:nth-of-type(2)"),
expected: [
"calc((1em * max(sibling-index(), 10)) + (min(2, sibling-count()) * 0.5rem))",
"calc((20px * max(2, 10)) + (min(2, 3) * 10px))",
"calc((20px * 10) + (min(2, 3) * 10px))",
"calc(200px + (min(2, 3) * 10px))",
"calc(200px + (2 * 10px))",
"calc(200px + 20px)",
"220px",
]
});
test({
expression: "calc(var(--on-main, 10px) + 3px)",
el: sectionEl,
expected: [
"calc(var(--on-main, 10px) + 3px)",
"calc(2em + 3px)",
"calc(48px + 3px)",
"51px",
]
});
test({
expression: "calc(var(--on-section, 0.1em) + var(--on-main, 0.2em) + attr(data-x px, 2px) + env(safe-area-inset-top, 1em))",
el: sectionEl,
expected: [
"calc(var(--on-section, 0.1em) + var(--on-main, 0.2em) + attr(data-x px, 2px) + env(safe-area-inset-top, 1em))",
"calc(1em + 2em + 10px + 0.0px)",
"calc(24px + 48px + 10px + 0px)",
"82px",
]
});
/// Expression with percentages
test({
property: "line-height",
expression: "calc(100% + 10px)",
el: sectionEl,
expected: [
"calc(100% + 10px)",
"calc(24px + 10px)",
"34px",
]
});
test({
property: "font-size",
expression: "calc(50% + 4px)",
el: sectionEl,
expected: [
"calc(50% + 4px)",
"calc(10px + 4px)",
"14px",
]
});
test({
property: "border-radius",
expression: "calc(50% + 4px)",
el: sectionEl,
expected: [
// We can't resolve the % for border-radius as it's a shorthand, so each longhand
// can have different values
"calc(50% + 4px)",
]
});
test({
property: "border-top-left-radius",
expression: "calc(50% + 4px)",
el: sectionEl,
expected: [
// We don't resolve border-radius shorthands either, as:
// - they can take 2 percentags that are mapping to different axis (e.g. `border-radius: 10% 15%`)
// - the percentages are not replaced for the computed value, so we'd need to think
// a bit more about it.
"calc(50% + 4px)",
]
});
test({
property: "margin-inline",
expression: "calc(25% + 4px)",
el: sectionEl,
// We're checking a shorthand, but the longhand this represents are all based on the
// same axis
expected: [
"calc(25% + 4px)",
"calc(50px + 4px)",
"54px",
]
});
test({
property: "margin",
expression: "calc(20% + 2px)",
el: sectionEl,
// We're checking a shorthand, but the longhand this represents are all based on the
// same axis
expected: [
"calc(20% + 2px)",
"calc(40px + 2px)",
"42px",
]
});
test({
property: "text-decoration-inset",
expression: "calc(50%)",
el: sectionEl,
expected: [
"calc(50%)",
"50%",
"50px",
]
});
test({
property: "text-decoration-inset",
expression: "calc(50% + var(--ten-percent))",
el: sectionEl,
expected: [
"calc(50% + var(--ten-percent))",
"calc(50% + 10%)",
"calc(50px + 10px)",
"60px",
]
});
test({
property: "--ten-percent",
expression: "calc(66% + 7px)",
el: sectionEl,
expected: [
// When declaring a property, we can't know what the percentage represents, it will
// depends on the property the variable is used for.
"calc(66% + 7px)",
]
});
test({
property: "text-decoration-inset",
expression: "calc(50%)",
el: firstLiEl,
expected: [
"calc(50%)",
// We can't resolve the % for text-decoration-inset can't be computed
// since the element has a box-decoration-break value of "clone"
"50%",
]
});
/// Indefinite block-size: percentage heights should not resolve
// width percentages still resolve since inline-size is definite
test({
property: "width",
expression: "calc(50%)",
el: childOfIndefiniteBlockSize,
expected: [
"calc(50%)",
"50%",
"100px",
]
});
test({
property: "height",
expression: "calc(50%)",
el: childOfIndefiniteBlockSize,
expected: [
"calc(50%)",
// height percentages don't resolve when the containing block's height is auto
"50%",
]
});
test({
property: "block-size",
expression: "calc(50%)",
el: childOfIndefiniteBlockSize,
expected: [
"calc(50%)",
// block-size percentages also don't resolve
"50%",
]
});
test({
property: "height",
expression: "calc(50%)",
el: zeroHeightAbsoluteChild,
expected: [
"calc(50%)",
// absolutely positioned elements: height percentages DO resolve even when the containing
// block's height is auto.
"50%",
// The containing block here has no in-flow content so its rendered
// height is 0px, giving 50% = 0px.
"0px",
]
});
test({
property: "height",
expression: "calc(50%)",
el: nonZeroHeightAbsoluteChild,
expected: [
"calc(50%)",
"50%",
// The containing block here do have in-flow content (`<aside>`) so it does
// have a non-zero height (50% of 80px = 40px).
"40px",
]
});
test({
property: "background-position-x",
expression: "calc(25% + 2px)",
el: sectionEl,
expected: [
// We don't resolve the % background-position-* yet as that requires to have access
// to the size of the background image.
"calc(25% + 2px)",
]
});
/// relative color computation
test({
// From `lch(from aquamarine l c calc(h + 180))`
expression: "calc(h + 180)",
el: sectionEl,
expected: []
});
test({
// From `lch(from aquamarine l c calc(h - 180))`
expression: "calc(h - 180)",
el: sectionEl,
expected: []
});
test({
// From `lch(from aquamarine l c calc(h * 2))`
expression: "calc(h * 2)",
el: sectionEl,
expected: []
});
test({
// From `lch(from aquamarine l c calc(h / 2))`
expression: "calc(h / 2)",
el: sectionEl,
expected: []
});
/// simple values
test({
// not super helpful, but the function should still handle this
expression: "10px",
el: sectionEl,
expected: ["10px"]
});
test({
expression: "1em",
el: sectionEl,
expected: ["1em", "24px"]
});
test({
expression: "2rem",
el: sectionEl,
expected: ["2rem", "40px"]
});
test({
expression: "10cqw",
el: sectionEl,
expected: ["10cqw", "20px"]
});
test({
expression: "10cqh",
el: sectionEl,
expected: ["10cqh", "10px"]
});
test({
expression: "10cqi",
el: sectionEl,
expected: ["10cqi", "20px"]
});
test({
expression: "10cqb",
el: sectionEl,
expected: ["10cqb", "10px"]
});
test({
expression: "10cqmin",
el: sectionEl,
expected: ["10cqmin", "10px"]
});
test({
expression: "10cqmax",
el: sectionEl,
expected: ["10cqmax", "20px"]
});
test({
expression: "10lh",
el: sectionEl,
expected: ["10lh", "280px"]
});
test({
expression: "10rlh",
el: sectionEl,
expected: ["10rlh", "240px"]
});
test({
property: "width",
expression: "10%",
el: sectionEl,
expected: ["10%","20px"]
});
test({
property: "height",
expression: "10%",
el: sectionEl,
expected: ["10%","10px"]
});
test({
expression: "10deg",
el: sectionEl,
// We shoul bail out for "<angle>"
expected: []
});
test({
expression: "10grad",
el: sectionEl,
// We shoul bail out for "<angle>"
expected: []
});
test({
expression: "10turn",
el: sectionEl,
// We shoul bail out for "<angle>"
expected: []
});
test({
expression: "1s",
el: sectionEl,
// We shoul bail out for "<time>"
expected: []
});
test({
expression: "1ms",
el: sectionEl,
// We shoul bail out for "<time>"
expected: []
});
test({
expression: "1Hz",
el: sectionEl,
// We shoul bail out for "<frequency>"
expected: []
});
test({
expression: "1orange",
el: sectionEl,
// We shoul bail out for made up units
expected: []
});
});
</script>
</body>
</html>