import { transformPropOrder } from '../../render/utils/keys-transform.mjs';

const translateAlias = {
    x: "translateX",
    y: "translateY",
    z: "translateZ",
    transformPerspective: "perspective",
};
function buildTransform(state) {
    let transform = "";
    let transformIsDefault = true;
    /**
     * Loop over all possible transforms in order, adding the ones that
     * are present to the transform string.
     */
    for (let i = 0; i < transformPropOrder.length; i++) {
        const key = transformPropOrder[i];
        const value = state.latest[key];
        if (value === undefined)
            continue;
        let valueIsDefault = true;
        if (typeof value === "number") {
            valueIsDefault = value === (key.startsWith("scale") ? 1 : 0);
        }
        else {
            const parsed = parseFloat(value);
            valueIsDefault = key.startsWith("scale") ? parsed === 1 : parsed === 0;
        }
        if (!valueIsDefault) {
            transformIsDefault = false;
            const transformName = translateAlias[key] || key;
            transform += `${transformName}(${value}) `;
        }
    }
    // See build-transform.ts: additive `rotate()` so user `rotate` isn't
    // clobbered. Not a `transformPropOrder` slot.
    const pathRotation = state.latest.pathRotation;
    if (pathRotation) {
        transformIsDefault = false;
        transform += `rotate(${typeof pathRotation === "number"
            ? `${pathRotation}deg`
            : pathRotation}) `;
    }
    return transformIsDefault ? "none" : transform.trim();
}

export { buildTransform };
//# sourceMappingURL=transform.mjs.map
