Skip to content

Truly independent web browser

3.0 KB
Raw Blame
<!DOCTYPE html>
<script src="../include.js"></script>
<style>
    @function --double(--value <length>) {
        result: calc(var(--value) * 2);
    }
    @function --attribute-default(--value: attr(data-size px)) {
        result: var(--value);
    }
    @function --outer-attribute() {
        --local: attr(data-size px);
        result: --inner-attribute();
    }
    @function --inner-attribute() {
        --local: inherit;
        result: var(--local);
    }
</style>
<script>
    test(() => {
        const parent = document.createElement("div");
        parent.style.setProperty("--inherited-order", "6");

        const element = document.createElement("div");
        element.setAttribute("data-size", "7");
        element.style.cssText = `
            --if-value: yes;
            width: --double(3px);
            height: env(unknown-environment-variable, 4px);
            margin-left: if(style(--if-value: yes): 5px; else: 6px);
            padding-top: --attribute-default();
            padding-right: --outer-attribute();
            padding-bottom: if(style((--if-value: yes) and (not (--missing))): 7px; else: 8px);
            z-index: inherit(--inherited-order);
            padding-left: attr(data-size px);
        `;
        parent.appendChild(element);
        document.body.appendChild(parent);

        internals.updateStyle();

        const style = getComputedStyle(element);
        println(`custom function: ${style.width}`);
        println(`environment fallback: ${style.height}`);
        println(`conditional: ${style.marginLeft}`);
        println(`custom function attribute default: ${style.paddingTop}`);
        println(`custom function inherited attribute: ${style.paddingRight}`);
        println(`compound conditional: ${style.paddingBottom}`);
        println(`inherit function: ${style.zIndex}`);
        println(`attribute: ${style.paddingLeft}`);
        element.style.setProperty("--if-value", "no");
        println(`conditional after mutation: ${getComputedStyle(element).marginLeft}`);
        println(`compound conditional after mutation: ${getComputedStyle(element).paddingBottom}`);
        parent.remove();

        CSS.registerProperty({
            name: "--non-inherited-order",
            syntax: "<integer>",
            inherits: false,
            initialValue: "0",
        });
        internals.updateStyle();
        const registeredParent = document.createElement("div");
        registeredParent.style.setProperty("--non-inherited-order", "8");
        const registeredChild = document.createElement("div");
        registeredChild.style.zIndex = "inherit(--non-inherited-order)";
        registeredParent.appendChild(registeredChild);
        document.body.appendChild(registeredParent);
        println(`registered inherit initial: ${getComputedStyle(registeredChild).zIndex}`);
        registeredParent.style.setProperty("--non-inherited-order", "9");
        println(`registered inherit mutation: ${getComputedStyle(registeredChild).zIndex}`);
    });
</script>