"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }


var _chunkYILQVUWXcjs = require('./chunk-YILQVUWX.cjs');


var _chunkC4IRH3TZcjs = require('./chunk-C4IRH3TZ.cjs');

// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/walker.js
var WalkerBase = class {
  static {
    _chunkC4IRH3TZcjs.__name.call(void 0, this, "WalkerBase");
  }
  constructor() {
    this.should_skip = false;
    this.should_remove = false;
    this.replacement = null;
    this.context = {
      skip: /* @__PURE__ */ _chunkC4IRH3TZcjs.__name.call(void 0, () => this.should_skip = true, "skip"),
      remove: /* @__PURE__ */ _chunkC4IRH3TZcjs.__name.call(void 0, () => this.should_remove = true, "remove"),
      replace: /* @__PURE__ */ _chunkC4IRH3TZcjs.__name.call(void 0, (node) => this.replacement = node, "replace")
    };
  }
  /**
  * @template {Node} Parent
  * @param {Parent | null | undefined} parent
  * @param {keyof Parent | null | undefined} prop
  * @param {number | null | undefined} index
  * @param {Node} node
  */
  replace(parent, prop, index, node) {
    if (parent && prop) {
      if (index != null) {
        parent[prop][index] = node;
      } else {
        parent[prop] = node;
      }
    }
  }
  /**
  * @template {Node} Parent
  * @param {Parent | null | undefined} parent
  * @param {keyof Parent | null | undefined} prop
  * @param {number | null | undefined} index
  */
  remove(parent, prop, index) {
    if (parent && prop) {
      if (index !== null && index !== void 0) {
        parent[prop].splice(index, 1);
      } else {
        delete parent[prop];
      }
    }
  }
};

// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/sync.js
var SyncWalker = class extends WalkerBase {
  static {
    _chunkC4IRH3TZcjs.__name.call(void 0, this, "SyncWalker");
  }
  /**
  *
  * @param {SyncHandler} [enter]
  * @param {SyncHandler} [leave]
  */
  constructor(enter, leave) {
    super();
    this.should_skip = false;
    this.should_remove = false;
    this.replacement = null;
    this.context = {
      skip: /* @__PURE__ */ _chunkC4IRH3TZcjs.__name.call(void 0, () => this.should_skip = true, "skip"),
      remove: /* @__PURE__ */ _chunkC4IRH3TZcjs.__name.call(void 0, () => this.should_remove = true, "remove"),
      replace: /* @__PURE__ */ _chunkC4IRH3TZcjs.__name.call(void 0, (node) => this.replacement = node, "replace")
    };
    this.enter = enter;
    this.leave = leave;
  }
  /**
  * @template {Node} Parent
  * @param {Node} node
  * @param {Parent | null} parent
  * @param {keyof Parent} [prop]
  * @param {number | null} [index]
  * @returns {Node | null}
  */
  visit(node, parent, prop, index) {
    if (node) {
      if (this.enter) {
        const _should_skip = this.should_skip;
        const _should_remove = this.should_remove;
        const _replacement = this.replacement;
        this.should_skip = false;
        this.should_remove = false;
        this.replacement = null;
        this.enter.call(this.context, node, parent, prop, index);
        if (this.replacement) {
          node = this.replacement;
          this.replace(parent, prop, index, node);
        }
        if (this.should_remove) {
          this.remove(parent, prop, index);
        }
        const skipped = this.should_skip;
        const removed = this.should_remove;
        this.should_skip = _should_skip;
        this.should_remove = _should_remove;
        this.replacement = _replacement;
        if (skipped) return node;
        if (removed) return null;
      }
      let key;
      for (key in node) {
        const value = node[key];
        if (value && typeof value === "object") {
          if (Array.isArray(value)) {
            const nodes = (
              /** @type {Array<unknown>} */
              value
            );
            for (let i = 0; i < nodes.length; i += 1) {
              const item = nodes[i];
              if (isNode(item)) {
                if (!this.visit(item, node, key, i)) {
                  i--;
                }
              }
            }
          } else if (isNode(value)) {
            this.visit(value, node, key, null);
          }
        }
      }
      if (this.leave) {
        const _replacement = this.replacement;
        const _should_remove = this.should_remove;
        this.replacement = null;
        this.should_remove = false;
        this.leave.call(this.context, node, parent, prop, index);
        if (this.replacement) {
          node = this.replacement;
          this.replace(parent, prop, index, node);
        }
        if (this.should_remove) {
          this.remove(parent, prop, index);
        }
        const removed = this.should_remove;
        this.replacement = _replacement;
        this.should_remove = _should_remove;
        if (removed) return null;
      }
    }
    return node;
  }
};
function isNode(value) {
  return value !== null && typeof value === "object" && "type" in value && typeof value.type === "string";
}
_chunkC4IRH3TZcjs.__name.call(void 0, isNode, "isNode");

// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/index.js
function walk(ast, { enter, leave }) {
  const instance = new SyncWalker(enter, leave);
  return instance.visit(ast, null);
}
_chunkC4IRH3TZcjs.__name.call(void 0, walk, "walk");

// ../../node_modules/.pnpm/unimport@3.14.5_rollup@4.29.1/node_modules/unimport/dist/chunks/detect-acorn.mjs
require('path');
require('process');
async function detectImportsAcorn(code, ctx, options) {
  const s = _chunkYILQVUWXcjs.getMagicString.call(void 0, code);
  const map = await ctx.getImportMap();
  let matchedImports = [];
  const enableAutoImport = _optionalChain([options, 'optionalAccess', _ => _.autoImport]) !== false;
  const enableTransformVirtualImports = _optionalChain([options, 'optionalAccess', _2 => _2.transformVirtualImports]) !== false && _optionalChain([ctx, 'access', _3 => _3.options, 'access', _4 => _4.virtualImports, 'optionalAccess', _5 => _5.length]);
  if (enableAutoImport || enableTransformVirtualImports) {
    const ast = _chunkYILQVUWXcjs.parse.call(void 0, s.original, {
      sourceType: "module",
      ecmaVersion: "latest",
      locations: true
    });
    const occurrenceMap = /* @__PURE__ */ new Map();
    const virtualImports = createVirtualImportsAcronWalker(map, ctx.options.virtualImports);
    const scopes = traveseScopes(
      ast,
      enableTransformVirtualImports ? virtualImports.walk : {}
    );
    if (enableAutoImport) {
      const identifiers = new Set(occurrenceMap.keys());
      matchedImports.push(
        ...Array.from(scopes.unmatched).map((name) => {
          const item = map.get(name);
          if (item && !item.disabled)
            return item;
          occurrenceMap.delete(name);
          return null;
        }).filter(Boolean)
      );
      for (const addon of ctx.addons)
        matchedImports = await _optionalChain([addon, 'access', _6 => _6.matchImports, 'optionalAccess', _7 => _7.call, 'call', _8 => _8(ctx, identifiers, matchedImports)]) || matchedImports;
    }
    virtualImports.ranges.forEach(([start, end]) => {
      s.remove(start, end);
    });
    matchedImports.push(...virtualImports.imports);
  }
  return {
    s,
    strippedCode: code.toString(),
    matchedImports,
    isCJSContext: false,
    firstOccurrence: 0
    // TODO:
  };
}
_chunkC4IRH3TZcjs.__name.call(void 0, detectImportsAcorn, "detectImportsAcorn");
function traveseScopes(ast, additionalWalk) {
  const scopes = [];
  let scopeCurrent = void 0;
  const scopesStack = [];
  function pushScope(node) {
    scopeCurrent = {
      node,
      parent: scopeCurrent,
      declarations: /* @__PURE__ */ new Set(),
      references: /* @__PURE__ */ new Set()
    };
    scopes.push(scopeCurrent);
    scopesStack.push(scopeCurrent);
  }
  _chunkC4IRH3TZcjs.__name.call(void 0, pushScope, "pushScope");
  function popScope(node) {
    const scope = scopesStack.pop();
    if (_optionalChain([scope, 'optionalAccess', _9 => _9.node]) !== node)
      throw new Error("Scope mismatch");
    scopeCurrent = scopesStack[scopesStack.length - 1];
  }
  _chunkC4IRH3TZcjs.__name.call(void 0, popScope, "popScope");
  pushScope(void 0);
  walk(ast, {
    enter(node, parent, prop, index) {
      _optionalChain([additionalWalk, 'optionalAccess', _10 => _10.enter, 'optionalAccess', _11 => _11.call, 'call', _12 => _12(this, node, parent, prop, index)]);
      switch (node.type) {
        case "ImportSpecifier":
        case "ImportDefaultSpecifier":
        case "ImportNamespaceSpecifier":
          scopeCurrent.declarations.add(node.local.name);
          return;
        case "FunctionDeclaration":
        case "ClassDeclaration":
          if (node.id)
            scopeCurrent.declarations.add(node.id.name);
          return;
        case "VariableDeclarator":
          if (node.id.type === "Identifier") {
            scopeCurrent.declarations.add(node.id.name);
          } else {
            walk(node.id, {
              enter(node2) {
                if (node2.type === "ObjectPattern") {
                  node2.properties.forEach((i) => {
                    if (i.type === "Property" && i.value.type === "Identifier")
                      scopeCurrent.declarations.add(i.value.name);
                    else if (i.type === "RestElement" && i.argument.type === "Identifier")
                      scopeCurrent.declarations.add(i.argument.name);
                  });
                } else if (node2.type === "ArrayPattern") {
                  node2.elements.forEach((i) => {
                    if (_optionalChain([i, 'optionalAccess', _13 => _13.type]) === "Identifier")
                      scopeCurrent.declarations.add(i.name);
                    if (_optionalChain([i, 'optionalAccess', _14 => _14.type]) === "RestElement" && i.argument.type === "Identifier")
                      scopeCurrent.declarations.add(i.argument.name);
                  });
                }
              }
            });
          }
          return;
        case "BlockStatement":
          pushScope(node);
          return;
        case "Identifier":
          switch (_optionalChain([parent, 'optionalAccess', _15 => _15.type])) {
            case "CallExpression":
              if (parent.callee === node || parent.arguments.includes(node))
                scopeCurrent.references.add(node.name);
              return;
            case "MemberExpression":
              if (parent.object === node)
                scopeCurrent.references.add(node.name);
              return;
            case "VariableDeclarator":
              if (parent.init === node)
                scopeCurrent.references.add(node.name);
              return;
            case "SpreadElement":
              if (parent.argument === node)
                scopeCurrent.references.add(node.name);
              return;
            case "ClassDeclaration":
              if (parent.superClass === node)
                scopeCurrent.references.add(node.name);
              return;
            case "Property":
              if (parent.value === node)
                scopeCurrent.references.add(node.name);
              return;
            case "TemplateLiteral":
              if (parent.expressions.includes(node))
                scopeCurrent.references.add(node.name);
              return;
            case "AssignmentExpression":
              if (parent.right === node)
                scopeCurrent.references.add(node.name);
              return;
            case "IfStatement":
            case "WhileStatement":
            case "DoWhileStatement":
              if (parent.test === node)
                scopeCurrent.references.add(node.name);
              return;
            case "SwitchStatement":
              if (parent.discriminant === node)
                scopeCurrent.references.add(node.name);
              return;
          }
          if (_optionalChain([parent, 'optionalAccess', _16 => _16.type, 'access', _17 => _17.includes, 'call', _18 => _18("Expression")]))
            scopeCurrent.references.add(node.name);
      }
    },
    leave(node, parent, prop, index) {
      _optionalChain([additionalWalk, 'optionalAccess', _19 => _19.leave, 'optionalAccess', _20 => _20.call, 'call', _21 => _21(this, node, parent, prop, index)]);
      switch (node.type) {
        case "BlockStatement":
          popScope(node);
      }
    }
  });
  const unmatched = /* @__PURE__ */ new Set();
  for (const scope of scopes) {
    for (const name of scope.references) {
      let defined = false;
      let parent = scope;
      while (parent) {
        if (parent.declarations.has(name)) {
          defined = true;
          break;
        }
        parent = _optionalChain([parent, 'optionalAccess', _22 => _22.parent]);
      }
      if (!defined)
        unmatched.add(name);
    }
  }
  return {
    unmatched,
    scopes
  };
}
_chunkC4IRH3TZcjs.__name.call(void 0, traveseScopes, "traveseScopes");
function createVirtualImportsAcronWalker(importMap, virtualImports = []) {
  const imports = [];
  const ranges = [];
  return {
    imports,
    ranges,
    walk: {
      enter(node) {
        if (node.type === "ImportDeclaration") {
          if (virtualImports.includes(node.source.value)) {
            ranges.push([node.start, node.end]);
            node.specifiers.forEach((i) => {
              if (i.type === "ImportSpecifier" && i.imported.type === "Identifier") {
                const original = importMap.get(i.imported.name);
                if (!original)
                  throw new Error(`[unimport] failed to find "${i.imported.name}" imported from "${node.source.value}"`);
                imports.push({
                  from: original.from,
                  name: original.name,
                  as: i.local.name
                });
              }
            });
          }
        }
      }
    }
  };
}
_chunkC4IRH3TZcjs.__name.call(void 0, createVirtualImportsAcronWalker, "createVirtualImportsAcronWalker");




exports.createVirtualImportsAcronWalker = createVirtualImportsAcronWalker; exports.detectImportsAcorn = detectImportsAcorn; exports.traveseScopes = traveseScopes;
