function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
/**
 * 应用上下文属性和配置到元素（纯函数版本）
 * @param el - 目标元素或元素数组
 * @param contextProps - 上下文属性对象
 * @param config - 配置对象
 * @returns 返回应用了属性和配置的新元素
 */ export var applyContextPropsAndConfig = function applyContextPropsAndConfig(el, contextProps, config) {
    var hasContextProps = Object.keys(contextProps || {}).length > 0;
    var hasConfig = Object.keys(config || {}).length > 0;
    var resolveAlign = function resolveAlign(item, res) {
        var _ref, _ref1, _ref2;
        var _res_otherProps, _item_otherProps;
        return (_ref = (_ref1 = (_ref2 = config === null || config === void 0 ? void 0 : config.align) !== null && _ref2 !== void 0 ? _ref2 : (_res_otherProps = res.otherProps) === null || _res_otherProps === void 0 ? void 0 : _res_otherProps.align) !== null && _ref1 !== void 0 ? _ref1 : (_item_otherProps = item.otherProps) === null || _item_otherProps === void 0 ? void 0 : _item_otherProps.align) !== null && _ref !== void 0 ? _ref : item.align;
    };
    if (Array.isArray(el)) {
        return el.map(function(item) {
            var result = _object_spread({}, item);
            if (hasContextProps) {
                result.contextProps = contextProps;
            }
            if (hasConfig && !item.otherProps) {
                result.otherProps = config;
            }
            var alignVal = resolveAlign(item, result);
            if (alignVal && (result.type === 'paragraph' || result.type === 'head')) {
                result.align = alignVal;
            }
            return result;
        });
    }
    var result = _object_spread({}, el);
    if (hasContextProps) {
        result.contextProps = contextProps;
    }
    if (hasConfig && !el.otherProps) {
        result.otherProps = config;
    }
    var alignVal = resolveAlign(el, result);
    if (alignVal && (result.type === 'paragraph' || result.type === 'head')) {
        result.align = alignVal;
    }
    return result;
};
