"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractTrait = void 0;
const Component_1 = require("../system/platform/component/Iframe/Component");
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 { $element } = leaf_comp;
    if (leaf_comp instanceof Component_1.default) {
        $element = leaf_comp._iframe_el;
    }
    // const leaf_context_position = {
    //   x: leaf_context.$x,
    //   y: leaf_context.$y,
    // }
    if ($element instanceof HTMLElement || $element instanceof SVGElement) {
        // const relative_position = getRelativePosition(
        //   $element,
        //   leaf_context.$element
        // )
        // let { x, y } = addVector(leaf_context_position, relative_position)
        let { width, height } = (0, getSize_1.getSize)($element);
        const { x, y } = (0, getPosition_1.getPosition)($element);
        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 ($element 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)($element));
        const position = (0, getPosition_1.getRelativePosition)($element, 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,
                sy: 1,
                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