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;
}
/**
 * 环境检测模块
 * 负责检测运行环境和提供适配能力
 */ /**
 * 运行环境类型
 */ export var RuntimeEnvironment = /*#__PURE__*/ function(RuntimeEnvironment) {
    /**
   * 浏览器环境
   */ RuntimeEnvironment["BROWSER"] = "browser";
    /**
   * 服务端渲染环境（SSR）
   */ RuntimeEnvironment["SSR"] = "ssr";
    /**
   * 微前端容器环境
   */ RuntimeEnvironment["MICRO_FRONTEND"] = "micro-frontend";
    /**
   * Node.js环境
   */ RuntimeEnvironment["NODE"] = "node";
    /**
   * 未知环境
   */ RuntimeEnvironment["UNKNOWN"] = "unknown";
    return RuntimeEnvironment;
}({});
/**
 * 环境检测器
 */ export class EnvironmentDetector {
    /**
   * 获取单例实例
   */ static getInstance() {
        if (!EnvironmentDetector.instance) {
            EnvironmentDetector.instance = new EnvironmentDetector();
        }
        return EnvironmentDetector.instance;
    }
    /**
   * 检测微前端环境
   */ detectMicroFrontend() {
        if (typeof window === 'undefined') {
            return false;
        }
        // 检测是否在微前端容器中
        // 常见的微前端框架标识
        return !!(window.__POWERED_BY_QIANKUN__ || window.__MICRO_APP_ENVIRONMENT__ || window.singleSpa || window.__SINGLE_SPA__);
    }
    /**
   * 检测运行环境
   */ detectEnvironment() {
        if (this.isMicroFrontend) {
            return "micro-frontend";
        }
        if (this.isSSR) {
            return "ssr";
        }
        if (this.isBrowser) {
            return "browser";
        }
        if (typeof process !== 'undefined') {
            return "node";
        }
        return "unknown";
    }
    /**
   * 获取当前运行环境
   */ getEnvironment() {
        return this.environment;
    }
    /**
   * 是否为浏览器环境
   */ isBrowserEnvironment() {
        return this.isBrowser;
    }
    /**
   * 是否为SSR环境
   */ isSSREnvironment() {
        return this.isSSR;
    }
    /**
   * 是否为微前端环境
   */ isMicroFrontendEnvironment() {
        return this.isMicroFrontend;
    }
    /**
   * 安全获取DOM元素（支持SSR）
   * 
   * @param selector - 选择器或元素ID
   * @returns DOM元素或null
   */ safeGetElement(selector) {
        if (!this.isBrowser) {
            return null;
        }
        if (typeof selector === 'function') {
            try {
                return selector();
            } catch  {
                return null;
            }
        }
        try {
            if (selector.startsWith('#')) {
                return document.getElementById(selector.slice(1));
            }
            return document.querySelector(selector);
        } catch  {
            return null;
        }
    }
    /**
   * 安全执行浏览器API（支持SSR）
   * 
   * @param fn - 要执行的函数
   * @param fallback - 非浏览器环境的回退值
   * @returns 执行结果或回退值
   */ safeExecuteBrowserAPI(fn, fallback) {
        if (!this.isBrowser) {
            return fallback;
        }
        try {
            return fn();
        } catch  {
            return fallback;
        }
    }
    constructor(){
        _define_property(this, "environment", void 0);
        _define_property(this, "isBrowser", void 0);
        _define_property(this, "isSSR", void 0);
        _define_property(this, "isMicroFrontend", void 0);
        this.isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
        this.isSSR = typeof window === 'undefined' && typeof process !== 'undefined';
        this.isMicroFrontend = this.detectMicroFrontend();
        this.environment = this.detectEnvironment();
    }
}
_define_property(EnvironmentDetector, "instance", null);
/**
 * 获取环境检测器实例
 */ export function getEnvironmentDetector() {
    return EnvironmentDetector.getInstance();
}

//# sourceMappingURL=environment.js.map