function _instanceof(left, right) {
    "@swc/helpers - instanceof";
    if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
        return !!right[Symbol.hasInstance](left);
    } else {
        return left instanceof right;
    }
}
function _type_of(obj) {
    "@swc/helpers - typeof";
    return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
/**
    Preps a config object for d3plus data, and optionally bubbles up a specific nested type. When using this function, you must bind a d3plus class' `this` context.
    @param config The configuration object to parse.
    @param type The event classifier to user for "on" events. For example, the default event type of "shape" will apply all events in the "on" config object with that key, like "click.shape" and "mouseleave.shape", in addition to any gloval events like "click" and "mouseleave".
    @param nest An optional nested key to bubble up to the parent config level.
*/ export default function configPrep() {
    var _this = this;
    var config = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this._shapeConfig, type = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "shape", nest = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
    var newConfig = {
        duration: this._duration,
        on: {}
    };
    var wrapFunction = function wrapFunction(func) {
        return function(d, i, s, e) {
            if (!func) return func;
            var parent;
            while(d.__d3plus__){
                if (parent) d.__d3plusParent__ = parent;
                parent = d;
                i = d.i;
                d = d.data || d.feature;
            }
            return func.bind(_this)(d, i, s || parent, e);
        };
    };
    var parseEvents = function parseEvents(newObj, on) {
        for(var event in on){
            if (({}).hasOwnProperty.call(on, event) && !event.includes(".") || event.includes(".".concat(type))) {
                newObj.on[event] = wrapFunction(on[event]);
            }
        }
    };
    var arrayEval = function arrayEval1(arr) {
        return arr.map(function(d) {
            if (_instanceof(d, Array)) return arrayEval(d);
            else if ((typeof d === "undefined" ? "undefined" : _type_of(d)) === "object") return keyEval({}, d);
            else if (typeof d === "function") return wrapFunction(d);
            else return d;
        });
    };
    var keyEval = function keyEval1(newObj, obj) {
        for(var key in obj){
            if (({}).hasOwnProperty.call(obj, key)) {
                if (key === "on") parseEvents(newObj, obj[key]);
                else if (typeof obj[key] === "function") {
                    newObj[key] = wrapFunction(obj[key]);
                } else if (_instanceof(obj[key], Array)) {
                    newObj[key] = arrayEval(obj[key]);
                } else if (_type_of(obj[key]) === "object") {
                    if (!newObj[key]) newObj[key] = {};
                    newObj[key].on = {};
                    keyEval(newObj[key], obj[key]);
                } else newObj[key] = obj[key];
            }
        }
        return newObj;
    };
    keyEval(newConfig, config);
    if (this._on) parseEvents(newConfig, this._on);
    if (nest && config[nest]) {
        keyEval(newConfig, config[nest]);
        if (config[nest].on) parseEvents(newConfig, config[nest].on);
    }
    return newConfig;
}
