"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 = (component, measureText) => {
    const leafContext = component.$context;
    let { $node } = component;
    if (component.$wrapElement && component.$wrapElement.isConnected) {
        $node = component.$wrapElement;
    }
    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 } = component.getScale();
        const fontSize = component.getFontSize();
        const opacity = component.getOpacity();
        const color = component.getColor();
        const background = component.getBackgroundColor();
        width /= Math.abs(sx);
        height /= Math.abs(sy);
        return { x, y, width, height, sx, sy, opacity, fontSize, color, background };
    }
    else if ($node instanceof Text) {
        const fontSize = component.getFontSize();
        let x;
        let y;
        let width;
        let height;
        let sx = 1;
        let sy = 1;
        let opacity = 1;
        let color;
        let background;
        ({ width, height } = (0, getSize_1.getSize)($node));
        let parentTrait;
        if (component.$parent) {
            parentTrait = (0, exports.extractTrait)(component.$parent, measureText);
            color = component.getColor();
        }
        else {
            const { $color } = component.$context;
            color = (0, color_1.hexToRgba)($color);
        }
        background = color_1.TRANSPARENT_RGBA;
        const position = (0, getPosition_1.getRelativePosition)($node, leafContext.$element);
        x = position.x;
        y = position.y;
        color = parentTrait.color;
        return {
            x,
            y,
            width,
            height,
            sx,
            sy,
            opacity,
            fontSize,
            color,
            background,
        };
    }
};
exports.extractTrait = extractTrait;
//# sourceMappingURL=extractTrait.js.map