"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractTrait = void 0;
const color_1 = require("./color");
const getPosition_1 = require("./util/style/getPosition");
const getSize_1 = require("./util/style/getSize");
const extractTrait = (leafComp, measureText) => {
    const leaf_context = leafComp.$context;
    let { $node } = leafComp;
    if ($node instanceof HTMLElement || $node instanceof SVGElement) {
        let { width, height } = (0, getSize_1.getSize)($node);
        const { x, y } = (0, getPosition_1.getPosition)($node);
        const { sx, sy } = leafComp.getScale();
        const fontSize = leafComp.getFontSize();
        const opacity = leafComp.getOpacity();
        const color = leafComp.getColor();
        width /= Math.abs(sx);
        height /= Math.abs(sy);
        return { x, y, width, height, sx, sy, opacity, fontSize, color };
    }
    else if ($node instanceof Text) {
        const fontSize = leafComp.getFontSize();
        let x;
        let y;
        let width;
        let height;
        let sx = 1;
        let sy = 1;
        let opacity = 1;
        let color;
        ({ width = width, height = height } = (0, getSize_1.getSize)($node));
        let parentTrait;
        if (leafComp.$parent) {
            parentTrait = (0, exports.extractTrait)(leafComp.$parent, measureText);
            color = leafComp.getColor();
        }
        else {
            const { $color } = leafComp.$context;
            color = (0, color_1.hexToRgba)($color);
        }
        const position = (0, getPosition_1.getRelativePosition)($node, leaf_context.$element);
        x = position.x;
        y = position.y;
        color = parentTrait.color;
        return {
            x,
            y,
            width,
            height,
            sx,
            sy,
            opacity,
            fontSize,
            color,
        };
    }
};
exports.extractTrait = extractTrait;
//# sourceMappingURL=extractTrait.js.map