"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractTrait = void 0;
const getPosition_1 = require("./util/style/getPosition");
const getSize_1 = require("./util/style/getSize");
const extractTrait = (leaf_comp, measureText) => {
    const leaf_context = leaf_comp.$context;
    let { $node } = leaf_comp;
    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 } = leaf_comp.getScale();
        const fontSize = leaf_comp.getFontSize();
        const opacity = leaf_comp.getOpacity();
        width /= Math.abs(sx);
        height /= Math.abs(sy);
        return { x, y, width, height, sx, sy, opacity, fontSize };
    }
    else if ($node instanceof Text) {
        const fontSize = leaf_comp.getFontSize();
        let x;
        let y;
        let width;
        let height;
        let sx = 1;
        let sy = 1;
        let opacity = 1;
        ({ width = width, height = height } = (0, getSize_1.getSize)($node));
        const position = (0, getPosition_1.getRelativePosition)($node, leaf_context.$element);
        let parent_trait;
        if (leaf_comp.$parent) {
            parent_trait = (0, exports.extractTrait)(leaf_comp.$parent, measureText);
        }
        else {
            parent_trait = {
                x: leaf_context.$x + 2,
                y: leaf_context.$y + 2,
                width: leaf_context.$width,
                height: leaf_context.$height,
                sx: 1, // TODO
                sy: 1, // TODO
                opacity: 1,
                fontSize,
            };
        }
        x = position.x;
        y = position.y;
        return {
            x,
            y,
            width,
            height,
            sx,
            sy,
            opacity,
            fontSize,
        };
    }
};
exports.extractTrait = extractTrait;
//# sourceMappingURL=extractTrait.js.map