"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/babel-plugin/index.ts
var index_exports = {};
__export(index_exports, {
  default: () => index_default
});
module.exports = __toCommonJS(index_exports);

// src/shared/attributes.ts
var ATTRS = {
  FILE_NAME: "x-file-name",
  LINE_NUMBER: "x-line-number",
  COLUMN: "x-column",
  COMPONENT: "x-component",
  ID: "x-id",
  DYNAMIC: "x-dynamic",
  EXCLUDED: "x-excluded",
  SOURCE_TYPE: "x-source-type",
  SOURCE_VAR: "x-source-var",
  SOURCE_FILE: "x-source-file",
  SOURCE_FILE_ABS: "x-source-file-abs",
  SOURCE_LINE: "x-source-line",
  SOURCE_PATH: "x-source-path",
  SOURCE_EDITABLE: "x-source-editable",
  ARRAY_VAR: "x-array-var",
  ARRAY_FILE: "x-array-file",
  ARRAY_LINE: "x-array-line",
  ARRAY_ITEM_PARAM: "x-array-item-param",
  ARRAY_INLINE: "x-array-inline",
  VE_DYNAMIC: "data-ve-dynamic"
};
var REQUIRED_ATTRS = [
  ATTRS.FILE_NAME,
  ATTRS.LINE_NUMBER,
  ATTRS.COMPONENT
];

// src/shared/excluded-components.ts
var EXCLUDED_COMPONENTS = /* @__PURE__ */ new Set([
  // React Router
  "Route",
  "Routes",
  "Switch",
  "Redirect",
  "Navigate",
  // React built-ins
  "Fragment",
  "Suspense",
  "StrictMode",
  // Other framework components
  "ErrorBoundary",
  "Provider",
  "Consumer",
  "Outlet",
  "Link",
  "NavLink",
  // Portal-based primitives (Radix/Floating-UI)
  "Sheet",
  "SheetContent",
  "SheetOverlay",
  "SheetPortal",
  "Popover",
  "PopoverContent",
  "Tooltip",
  "TooltipContent",
  "DropdownMenu",
  "DropdownMenuContent",
  "DropdownMenuSubContent",
  "ContextMenu",
  "ContextMenuContent",
  "ContextMenuSubContent",
  "HoverCard",
  "HoverCardContent",
  "Select",
  "SelectContent",
  "Menubar",
  "MenubarContent",
  "MenubarSubContent",
  "MenubarPortal",
  "Drawer",
  "DrawerContent",
  "DrawerOverlay",
  "DrawerPortal",
  "Toast",
  "ToastViewport",
  "NavigationMenu",
  "NavigationMenuContent",
  "DropdownMenuPortal",
  "ContextMenuPortal",
  "Command",
  "CommandDialog",
  // Triggers & measured bits
  "PopoverTrigger",
  "TooltipTrigger",
  "DropdownMenuTrigger",
  "ContextMenuTrigger",
  "HoverCardTrigger",
  "SelectTrigger",
  "MenubarTrigger",
  "NavigationMenuTrigger",
  "SheetTrigger",
  "DrawerTrigger",
  "CommandInput",
  "Slot",
  // Icons (avoid wrapping)
  "X",
  "ChevronRight",
  "ChevronLeft",
  "ChevronUp",
  "ChevronDown",
  "Check",
  "Plus",
  "Minus",
  "Search",
  "Menu",
  "Settings",
  "User",
  "Home",
  "ArrowRight",
  "ArrowLeft"
]);
var RADIX_ROOTS = /* @__PURE__ */ new Set([
  "Dialog",
  "Popover",
  "Tooltip",
  "DropdownMenu",
  "ContextMenu",
  "AlertDialog",
  "HoverCard",
  "Select",
  "Menubar",
  "NavigationMenu",
  "Sheet",
  "Drawer",
  "Toast",
  "Command"
]);
var PORTAL_SUFFIX_RE = /(Trigger|Portal|Content|Overlay|Viewport|Anchor|Arrow)$/;
var ARRAY_METHODS = /* @__PURE__ */ new Set([
  "map",
  "forEach",
  "filter",
  "reduce",
  "reduceRight",
  "flatMap",
  "find",
  "findIndex",
  "some",
  "every"
]);
function isPortalishName(name) {
  if (!name) return false;
  return RADIX_ROOTS.has(name) || PORTAL_SUFFIX_RE.test(name);
}

// src/babel-plugin/helpers/jsx-utils.ts
function jsxNameOf(openingEl, t) {
  const n = openingEl?.name;
  if (t.isJSXIdentifier(n)) return n.name;
  if (t.isJSXMemberExpression(n)) return n.property.name;
  return null;
}
function createJsxUtils(t) {
  const getName = (openingEl) => {
    const n = openingEl?.name;
    if (t.isJSXIdentifier(n)) return n.name;
    if (t.isJSXMemberExpression(n)) return n.property.name;
    return null;
  };
  function getJSXElementName(openingElement) {
    const n = openingElement?.name;
    if (t.isJSXIdentifier(n)) return n.name;
    if (t.isJSXMemberExpression(n)) return n.property.name;
    return null;
  }
  function getContainingComponentName(exprPath) {
    let current = exprPath;
    while (current) {
      if (current.isFunctionDeclaration() && current.node.id) {
        return current.node.id.name;
      }
      if (current.isVariableDeclarator() && t.isIdentifier(current.node.id)) {
        return current.node.id.name;
      }
      if (current.isArrowFunctionExpression() || current.isFunctionExpression()) {
        const parent = current.parentPath;
        if (parent && parent.isVariableDeclarator() && t.isIdentifier(parent.node.id)) {
          return parent.node.id.name;
        }
      }
      current = current.parentPath;
    }
    return null;
  }
  const hasProp = (openingEl, name) => openingEl?.attributes?.some(
    (a) => t.isJSXAttribute(a) && t.isJSXIdentifier(a.name) && a.name.name === name
  );
  const isPortalPrimitive = (name) => PORTAL_SUFFIX_RE.test(name);
  const isDirectChildOfAsChildOrTrigger = (jsxPath) => {
    const p = jsxPath.parentPath;
    if (!p || !p.isJSXElement || !p.isJSXElement()) return false;
    const open = p.node.openingElement;
    const name = getName(open) || "";
    return hasProp(open, "asChild") || /Trigger$/.test(name) || name === "Slot";
  };
  const alreadyHasXMeta = (openingEl) => openingEl.attributes?.some(
    (a) => t.isJSXAttribute(a) && t.isJSXIdentifier(a.name) && a.name.name.startsWith("x-")
  );
  const insertMetaAttributes = (openingEl, attrsToAdd) => {
    if (!openingEl.attributes) openingEl.attributes = [];
    const spreadIndex = openingEl.attributes.findIndex(
      (attr) => t.isJSXSpreadAttribute(attr)
    );
    if (spreadIndex === -1) {
      openingEl.attributes.push(...attrsToAdd);
    } else {
      openingEl.attributes.splice(spreadIndex, 0, ...attrsToAdd);
    }
  };
  const pushMetaAttrs = (openingEl, { normalizedPath, lineNumber, column, elementName, isDynamic, sourceInfo, arrayContext }, { markExcluded = false } = {}) => {
    if (alreadyHasXMeta(openingEl)) return;
    const col = column || 0;
    const metaAttrs = [
      t.jsxAttribute(t.jsxIdentifier(ATTRS.FILE_NAME), t.stringLiteral(normalizedPath)),
      t.jsxAttribute(t.jsxIdentifier(ATTRS.LINE_NUMBER), t.stringLiteral(String(lineNumber))),
      t.jsxAttribute(t.jsxIdentifier(ATTRS.COLUMN), t.stringLiteral(String(col))),
      t.jsxAttribute(t.jsxIdentifier(ATTRS.COMPONENT), t.stringLiteral(elementName)),
      t.jsxAttribute(t.jsxIdentifier(ATTRS.ID), t.stringLiteral(`${normalizedPath}_${lineNumber}_${col}`)),
      t.jsxAttribute(t.jsxIdentifier(ATTRS.DYNAMIC), t.stringLiteral(isDynamic ? "true" : "false"))
    ];
    if (markExcluded) {
      metaAttrs.push(
        t.jsxAttribute(t.jsxIdentifier(ATTRS.EXCLUDED), t.stringLiteral("true"))
      );
    }
    if (sourceInfo) {
      if (sourceInfo.type) {
        metaAttrs.push(t.jsxAttribute(t.jsxIdentifier(ATTRS.SOURCE_TYPE), t.stringLiteral(sourceInfo.type)));
      }
      if (sourceInfo.varName) {
        metaAttrs.push(t.jsxAttribute(t.jsxIdentifier(ATTRS.SOURCE_VAR), t.stringLiteral(sourceInfo.varName)));
      }
      if (sourceInfo.file) {
        metaAttrs.push(t.jsxAttribute(t.jsxIdentifier(ATTRS.SOURCE_FILE), t.stringLiteral(sourceInfo.file)));
      }
      if (sourceInfo.absFile) {
        metaAttrs.push(t.jsxAttribute(t.jsxIdentifier(ATTRS.SOURCE_FILE_ABS), t.stringLiteral(sourceInfo.absFile)));
      }
      if (sourceInfo.line) {
        metaAttrs.push(t.jsxAttribute(t.jsxIdentifier(ATTRS.SOURCE_LINE), t.stringLiteral(String(sourceInfo.line))));
      }
      if (sourceInfo.path) {
        metaAttrs.push(t.jsxAttribute(t.jsxIdentifier(ATTRS.SOURCE_PATH), t.stringLiteral(sourceInfo.path)));
      }
      metaAttrs.push(
        t.jsxAttribute(t.jsxIdentifier(ATTRS.SOURCE_EDITABLE), t.stringLiteral(sourceInfo.isEditable ? "true" : "false"))
      );
    }
    if (arrayContext) {
      if (arrayContext.arrayVar) {
        metaAttrs.push(t.jsxAttribute(t.jsxIdentifier(ATTRS.ARRAY_VAR), t.stringLiteral(arrayContext.arrayVar)));
      }
      if (arrayContext.arrayFile) {
        metaAttrs.push(t.jsxAttribute(t.jsxIdentifier(ATTRS.ARRAY_FILE), t.stringLiteral(arrayContext.arrayFile)));
      }
      if (arrayContext.arrayLine) {
        metaAttrs.push(t.jsxAttribute(t.jsxIdentifier(ATTRS.ARRAY_LINE), t.stringLiteral(String(arrayContext.arrayLine))));
      }
      if (arrayContext.itemParam) {
        metaAttrs.push(t.jsxAttribute(t.jsxIdentifier(ATTRS.ARRAY_ITEM_PARAM), t.stringLiteral(arrayContext.itemParam)));
      }
      if (arrayContext.isInlineArray) {
        metaAttrs.push(t.jsxAttribute(t.jsxIdentifier(ATTRS.ARRAY_INLINE), t.stringLiteral("true")));
      }
    }
    insertMetaAttributes(openingEl, metaAttrs);
  };
  return {
    getName,
    getJSXElementName,
    getContainingComponentName,
    hasProp,
    isPortalPrimitive,
    isDirectChildOfAsChildOrTrigger,
    alreadyHasXMeta,
    insertMetaAttributes,
    pushMetaAttrs
  };
}

// src/babel-plugin/analysis/cross-file-resolver.ts
var import_path = __toESM(require("path"));
var import_fs = __toESM(require("fs"));

// src/babel-plugin/helpers/caches.ts
var RESOLVE_CACHE = /* @__PURE__ */ new Map();
var FILE_AST_CACHE = /* @__PURE__ */ new Map();
var PORTAL_COMP_CACHE = /* @__PURE__ */ new Map();
var DYNAMIC_COMP_CACHE = /* @__PURE__ */ new Map();
var BINDING_DYNAMIC_CACHE = /* @__PURE__ */ new WeakMap();
var PROP_SOURCE_CACHE = /* @__PURE__ */ new Map();

// src/babel-plugin/analysis/cross-file-resolver.ts
var EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
var PROJECT_ROOT = process.cwd();
var SRC_ALIAS = import_path.default.resolve(PROJECT_ROOT, "src");
function resolveImportPath(source, fromFile) {
  const cacheKey = `${fromFile}::${source}`;
  if (RESOLVE_CACHE.has(cacheKey)) return RESOLVE_CACHE.get(cacheKey) ?? null;
  let base;
  if (source.startsWith("@/")) {
    base = import_path.default.join(SRC_ALIAS, source.slice(2));
  } else if (source.startsWith("./") || source.startsWith("../")) {
    base = import_path.default.resolve(import_path.default.dirname(fromFile), source);
  } else {
    RESOLVE_CACHE.set(cacheKey, null);
    return null;
  }
  for (const ext of EXTENSIONS) {
    const file = base.endsWith(ext) ? base : base + ext;
    if (import_fs.default.existsSync(file) && import_fs.default.statSync(file).isFile()) {
      RESOLVE_CACHE.set(cacheKey, file);
      return file;
    }
  }
  if (import_fs.default.existsSync(base) && import_fs.default.statSync(base).isDirectory()) {
    for (const ext of EXTENSIONS) {
      const idx = import_path.default.join(base, "index" + ext);
      if (import_fs.default.existsSync(idx)) {
        RESOLVE_CACHE.set(cacheKey, idx);
        return idx;
      }
    }
  }
  RESOLVE_CACHE.set(cacheKey, null);
  return null;
}
function getComponentSourcePath(binding, state) {
  if (!binding || !binding.path) return null;
  const bindingPath = binding.path;
  const fileFrom = state.filename || state.file?.opts?.filename || __filename;
  if (bindingPath.isImportSpecifier()) {
    const from = bindingPath.parent.source.value;
    return resolveImportPath(from, fileFrom);
  }
  if (bindingPath.isImportDefaultSpecifier()) {
    const from = bindingPath.parent.source.value;
    return resolveImportPath(from, fileFrom);
  }
  return null;
}
function parseFileAst(absPath, parser) {
  try {
    const stat = import_fs.default.statSync(absPath);
    const cached = FILE_AST_CACHE.get(absPath);
    if (cached && cached.mtimeMs === stat.mtimeMs) return cached.ast;
    const code = import_fs.default.readFileSync(absPath, "utf8");
    const ast = parser.parse(code, {
      sourceType: "module",
      plugins: ["jsx", "typescript"]
    });
    FILE_AST_CACHE.set(absPath, { ast, mtimeMs: stat.mtimeMs });
    return ast;
  } catch (error) {
    return null;
  }
}
function createCrossFileResolver(t) {
  function findExportedVariableInfo(absPath, exportName) {
    const parser = require("@babel/parser");
    const traverse = require("@babel/traverse").default;
    const ast = parseFileAst(absPath, parser);
    if (!ast) return null;
    let result = null;
    traverse(ast, {
      // Check export const VARIABLE = value
      ExportNamedDeclaration(p) {
        if (result) return;
        if (p.node.declaration && t.isVariableDeclaration(p.node.declaration)) {
          const decl = p.node.declaration;
          for (const declarator of decl.declarations) {
            if (t.isIdentifier(declarator.id) && declarator.id.name === exportName) {
              const init = declarator.init;
              let valueType = null;
              let isEditable = false;
              if (t.isStringLiteral(init) || t.isNumericLiteral(init)) {
                valueType = "literal";
                isEditable = true;
              } else if (t.isArrayExpression(init)) {
                valueType = "array";
                isEditable = true;
              } else if (t.isObjectExpression(init)) {
                valueType = "object";
                isEditable = true;
              }
              result = {
                line: declarator.loc?.start.line || null,
                valueType,
                isEditable
              };
              return;
            }
          }
        }
        if (p.node.specifiers) {
          for (const spec of p.node.specifiers) {
            if (t.isExportSpecifier(spec) && t.isIdentifier(spec.exported) && spec.exported.name === exportName) {
              const localName = t.isIdentifier(spec.local) ? spec.local.name : exportName;
              const binding = p.scope.getBinding(localName);
              if (binding && binding.path.isVariableDeclarator()) {
                const init = binding.path.node.init;
                let valueType = null;
                let isEditable = false;
                if (t.isStringLiteral(init) || t.isNumericLiteral(init)) {
                  valueType = "literal";
                  isEditable = true;
                } else if (t.isArrayExpression(init)) {
                  valueType = "array";
                  isEditable = true;
                } else if (t.isObjectExpression(init)) {
                  valueType = "object";
                  isEditable = true;
                }
                result = {
                  line: binding.path.node.loc?.start.line || null,
                  valueType,
                  isEditable
                };
              }
              return;
            }
          }
        }
      }
    });
    return result;
  }
  return { findExportedVariableInfo };
}

// src/shared/source-types.ts
var SOURCE_TYPE = {
  STATIC_LOCAL: "static-local",
  STATIC_IMPORTED: "static-imported",
  PROP: "prop",
  STATE: "state",
  COMPUTED: "computed",
  TEMPLATE: "template",
  EXTERNAL: "external",
  UNKNOWN: "unknown"
};
var EDITABLE_SOURCE_TYPES = /* @__PURE__ */ new Set([
  SOURCE_TYPE.STATIC_LOCAL,
  SOURCE_TYPE.STATIC_IMPORTED
]);
var READONLY_SOURCE_TYPES = /* @__PURE__ */ new Set([
  SOURCE_TYPE.PROP,
  SOURCE_TYPE.STATE,
  SOURCE_TYPE.COMPUTED,
  SOURCE_TYPE.EXTERNAL
]);

// src/babel-plugin/analysis/expression-analyzer.ts
function createExpressionAnalyzer(t, deps) {
  const {
    getArrayIterationContext,
    getContainingComponentName,
    tracePropToSource,
    findExportedVariableInfo
  } = deps;
  function buildPropertyPath(node) {
    const parts = [];
    let current = node;
    while (t.isMemberExpression(current)) {
      if (t.isIdentifier(current.property)) {
        parts.unshift(current.property.name);
      } else if (t.isNumericLiteral(current.property)) {
        parts.unshift(`[${current.property.value}]`);
      } else if (t.isStringLiteral(current.property)) {
        parts.unshift(current.property.value);
      }
      current = current.object;
    }
    return parts.join(".");
  }
  function analyzeExpression(exprPath, state) {
    if (!exprPath || !exprPath.node) return null;
    const node = exprPath.node;
    if (t.isIdentifier(node)) {
      return analyzeIdentifier(node.name, exprPath, state);
    }
    if (t.isMemberExpression(node)) {
      return analyzeMemberExpression(exprPath, state);
    }
    if (t.isCallExpression(node)) {
      return { type: SOURCE_TYPE.COMPUTED, isEditable: false };
    }
    if (t.isTemplateLiteral(node)) {
      return { type: SOURCE_TYPE.TEMPLATE, isEditable: false };
    }
    if (t.isConditionalExpression(node)) {
      return { type: SOURCE_TYPE.COMPUTED, isEditable: false };
    }
    if (t.isLogicalExpression(node)) {
      return { type: SOURCE_TYPE.COMPUTED, isEditable: false };
    }
    if (t.isBinaryExpression(node)) {
      return { type: SOURCE_TYPE.COMPUTED, isEditable: false };
    }
    return { type: SOURCE_TYPE.UNKNOWN, isEditable: false };
  }
  function analyzeIdentifier(name, exprPath, state, options = {}) {
    const { skipArrayContext = false } = options;
    const binding = exprPath.scope.getBinding(name);
    if (!binding) {
      return { type: SOURCE_TYPE.EXTERNAL, varName: name, isEditable: false };
    }
    const bindingPath = binding.path;
    if (!skipArrayContext) {
      const arrayContext = getArrayIterationContext(exprPath, state);
      if (arrayContext && arrayContext.itemParam === name) {
        return {
          type: arrayContext.isInlineArray ? SOURCE_TYPE.STATIC_LOCAL : SOURCE_TYPE.STATIC_IMPORTED,
          varName: arrayContext.arrayVar,
          file: arrayContext.arrayFile,
          absFile: arrayContext.absFile,
          line: arrayContext.arrayLine,
          isEditable: arrayContext.isEditable,
          valueType: "array-item",
          arrayContext
        };
      }
    }
    if (bindingPath.isIdentifier() && bindingPath.parentPath.isFunctionDeclaration()) {
      const componentName = getContainingComponentName(exprPath);
      const tracedSource = tracePropToSource(name, componentName, exprPath, state);
      if (tracedSource && tracedSource.isEditable) {
        return {
          type: SOURCE_TYPE.PROP,
          varName: tracedSource.varName,
          propName: name,
          tracedFrom: tracedSource,
          file: tracedSource.file,
          absFile: tracedSource.absFile,
          line: tracedSource.line,
          path: tracedSource.path,
          isEditable: true,
          arrayContext: tracedSource.arrayContext
        };
      }
      return { type: SOURCE_TYPE.PROP, varName: name, isEditable: false };
    }
    if (bindingPath.isObjectPattern() || bindingPath.parentPath && bindingPath.parentPath.isObjectPattern()) {
      const funcParent = bindingPath.findParent(
        (p) => p.isFunctionDeclaration() || p.isArrowFunctionExpression() || p.isFunctionExpression()
      );
      if (funcParent && funcParent.node.params.some((param) => {
        if (t.isIdentifier(param)) return false;
        if (t.isObjectPattern(param)) return true;
        return false;
      })) {
        const componentName = getContainingComponentName(exprPath);
        const tracedSource = tracePropToSource(name, componentName, exprPath, state);
        if (tracedSource && tracedSource.isEditable) {
          return {
            type: SOURCE_TYPE.PROP,
            varName: tracedSource.varName,
            propName: name,
            tracedFrom: tracedSource,
            file: tracedSource.file,
            absFile: tracedSource.absFile,
            line: tracedSource.line,
            path: tracedSource.path,
            isEditable: true,
            arrayContext: tracedSource.arrayContext
          };
        }
        return { type: SOURCE_TYPE.PROP, varName: name, isEditable: false };
      }
    }
    if (bindingPath.isVariableDeclarator()) {
      const init = bindingPath.node.init;
      if (t.isCallExpression(init) && t.isIdentifier(init.callee)) {
        const calleeName = init.callee.name;
        if (calleeName === "useState" || calleeName === "useReducer" || calleeName === "useContext" || calleeName === "useMemo" || calleeName === "useCallback") {
          return { type: SOURCE_TYPE.STATE, varName: name, isEditable: false };
        }
      }
    }
    if (bindingPath.isImportSpecifier() || bindingPath.isImportDefaultSpecifier()) {
      const importDecl = bindingPath.parentPath.node;
      const source = importDecl.source.value;
      if (source.startsWith("@/") || source.startsWith("./") || source.startsWith("../")) {
        const fileFrom = state.filename || state.file?.opts?.filename || __filename;
        const absPath = resolveImportPath(source, fileFrom);
        if (absPath) {
          let exportName = name;
          if (bindingPath.isImportSpecifier() && t.isIdentifier(bindingPath.node.imported)) {
            exportName = bindingPath.node.imported.name;
          }
          const varInfo = findExportedVariableInfo(absPath, exportName);
          return {
            type: SOURCE_TYPE.STATIC_IMPORTED,
            varName: exportName,
            file: source,
            absFile: absPath,
            line: varInfo?.line || null,
            isEditable: varInfo?.isEditable || false,
            valueType: varInfo?.valueType || null
          };
        }
      }
      return { type: SOURCE_TYPE.EXTERNAL, varName: name, isEditable: false };
    }
    if (bindingPath.isVariableDeclarator()) {
      const parent = bindingPath.parentPath;
      if (parent.isVariableDeclaration() && parent.node.kind === "const") {
        const init = bindingPath.node.init;
        const currentFile = state.filename || state.file?.opts?.filename || null;
        if (t.isStringLiteral(init) || t.isNumericLiteral(init)) {
          return {
            type: SOURCE_TYPE.STATIC_LOCAL,
            varName: name,
            absFile: currentFile,
            line: bindingPath.node.loc?.start.line || null,
            isEditable: true,
            valueType: "literal"
          };
        }
        if (t.isArrayExpression(init)) {
          return {
            type: SOURCE_TYPE.STATIC_LOCAL,
            varName: name,
            absFile: currentFile,
            line: bindingPath.node.loc?.start.line || null,
            isEditable: true,
            valueType: "array"
          };
        }
        if (t.isObjectExpression(init)) {
          return {
            type: SOURCE_TYPE.STATIC_LOCAL,
            varName: name,
            absFile: currentFile,
            line: bindingPath.node.loc?.start.line || null,
            isEditable: true,
            valueType: "object"
          };
        }
      }
    }
    return { type: SOURCE_TYPE.UNKNOWN, varName: name, isEditable: false };
  }
  function analyzeMemberExpression(exprPath, state, options = {}) {
    const node = exprPath.node;
    const propPath = buildPropertyPath(node);
    let root = node;
    while (t.isMemberExpression(root.object)) {
      root = root.object;
    }
    const rootObj = root.object;
    if (t.isIdentifier(rootObj)) {
      const rootName = rootObj.name;
      const arrayContext = options.skipArrayContext ? null : getArrayIterationContext(exprPath, state);
      if (arrayContext && arrayContext.itemParam === rootName) {
        const fullPath = arrayContext.arrayPath ? `${arrayContext.arrayPath}.${propPath}` : propPath;
        return {
          type: arrayContext.isInlineArray ? SOURCE_TYPE.STATIC_LOCAL : SOURCE_TYPE.STATIC_IMPORTED,
          varName: arrayContext.arrayVar,
          file: arrayContext.arrayFile,
          absFile: arrayContext.absFile,
          line: arrayContext.arrayLine,
          path: fullPath,
          isEditable: arrayContext.isEditable,
          valueType: "array-item",
          arrayContext
        };
      }
      const rootInfo = analyzeIdentifier(rootName, exprPath, state, options);
      if (rootInfo) {
        if (rootInfo.isEditable && propPath === "length" && (rootInfo.valueType === "array" || rootInfo.valueType === "literal")) {
          return {
            ...rootInfo,
            type: SOURCE_TYPE.COMPUTED,
            path: propPath,
            isEditable: false
          };
        }
        return {
          ...rootInfo,
          path: propPath
        };
      }
    }
    return { type: SOURCE_TYPE.UNKNOWN, path: propPath, isEditable: false };
  }
  return {
    analyzeExpression,
    analyzeIdentifier,
    analyzeMemberExpression,
    buildPropertyPath
  };
}

// src/babel-plugin/analysis/array-context.ts
function createArrayContext(t, deps) {
  const { analyzeIdentifier, analyzeMemberExpression } = deps;
  function getArrayIterationContext(exprPath, state) {
    const callExprParent = exprPath.findParent((p) => {
      if (!p.isCallExpression()) return false;
      const { callee: callee2 } = p.node;
      if (!t.isMemberExpression(callee2) || !t.isIdentifier(callee2.property)) {
        return false;
      }
      return ARRAY_METHODS.has(callee2.property.name);
    });
    if (!callExprParent) return null;
    const callExpr = callExprParent.node;
    const callee = callExpr.callee;
    const arrayNode = callee.object;
    const callback = callExpr.arguments[0];
    if (!callback) return null;
    let itemParam = null;
    let indexParam = null;
    if (t.isArrowFunctionExpression(callback) || t.isFunctionExpression(callback)) {
      const params = callback.params;
      if (params.length > 0 && t.isIdentifier(params[0])) {
        itemParam = params[0].name;
      }
      if (params.length > 1 && t.isIdentifier(params[1])) {
        indexParam = params[1].name;
      }
    }
    if (!itemParam) return null;
    let arrayVar = null;
    let arrayFile = null;
    let absFile = null;
    let arrayLine = null;
    let isEditable = false;
    if (t.isIdentifier(arrayNode)) {
      arrayVar = arrayNode.name;
      const arrayInfo = analyzeIdentifier(arrayVar, callExprParent.get("callee.object"), state, { skipArrayContext: true });
      if (arrayInfo) {
        arrayFile = arrayInfo.file || null;
        absFile = arrayInfo.absFile || null;
        arrayLine = arrayInfo.line || null;
        isEditable = arrayInfo.isEditable && arrayInfo.valueType === "array";
      }
    } else if (t.isMemberExpression(arrayNode)) {
      const memberInfo = analyzeMemberExpression(
        callExprParent.get("callee.object"),
        state,
        { skipArrayContext: true }
      );
      if (memberInfo) {
        arrayVar = memberInfo.varName;
        arrayFile = memberInfo.file || null;
        absFile = memberInfo.absFile || null;
        arrayLine = memberInfo.line || null;
        isEditable = memberInfo.isEditable || false;
      }
    } else if (t.isArrayExpression(arrayNode)) {
      const currentFile = state.filename || state.file?.opts?.filename || null;
      arrayVar = null;
      arrayFile = currentFile;
      absFile = currentFile;
      arrayLine = arrayNode.loc?.start.line || null;
      isEditable = true;
    }
    let arrayPath = null;
    if (t.isMemberExpression(arrayNode)) {
      const parts = [];
      let node = arrayNode;
      while (t.isMemberExpression(node)) {
        if (t.isIdentifier(node.property)) {
          parts.unshift(node.property.name);
        }
        node = node.object;
      }
      if (parts.length > 0) {
        arrayPath = parts.join(".");
      }
    }
    return {
      arrayVar,
      arrayFile,
      absFile,
      arrayLine,
      itemParam,
      indexParam,
      isEditable,
      arrayPath,
      isInlineArray: t.isArrayExpression(arrayNode)
    };
  }
  return { getArrayIterationContext };
}

// src/babel-plugin/analysis/prop-source-tracker.ts
function createPropSourceTracker(t, deps) {
  const {
    analyzeExpression,
    getArrayIterationContext,
    getJSXElementName,
    getContainingComponentName
  } = deps;
  function tracePropToSource(propName, componentName, exprPath, state) {
    if (!componentName) return null;
    const programPath = exprPath.findParent((p) => p.isProgram());
    if (!programPath) return null;
    let tracedSource = null;
    programPath.traverse({
      JSXOpeningElement(jsxPath) {
        if (tracedSource) return;
        const elementName = getJSXElementName(jsxPath.node);
        if (elementName !== componentName) return;
        for (const attr of jsxPath.node.attributes || []) {
          if (!t.isJSXAttribute(attr)) continue;
          if (!t.isJSXIdentifier(attr.name) || attr.name.name !== propName) continue;
          if (!t.isJSXExpressionContainer(attr.value)) continue;
          const attrs = jsxPath.get("attributes");
          const attrPath = attrs.find(
            (a) => a.isJSXAttribute() && t.isJSXIdentifier(a.node.name) && a.node.name.name === propName
          );
          if (attrPath) {
            const valuePath = attrPath.get("value");
            if (valuePath && valuePath.isJSXExpressionContainer()) {
              const innerExpr = valuePath.get("expression");
              if (innerExpr && innerExpr.node) {
                tracedSource = analyzeExpression(innerExpr, state);
              }
            }
          }
        }
      }
    });
    if (tracedSource) return tracedSource;
    return lookupCrossFilePropSource(propName, componentName, state);
  }
  function recordPropSources(componentName, jsxPath, state) {
    const binding = jsxPath.scope.getBinding(componentName);
    if (!binding) return;
    const componentAbsPath = getComponentSourcePath(binding, state);
    if (!componentAbsPath) return;
    const openingElement = jsxPath.node.openingElement;
    for (const attr of openingElement.attributes || []) {
      if (!t.isJSXAttribute(attr)) continue;
      if (!t.isJSXIdentifier(attr.name)) continue;
      if (!t.isJSXExpressionContainer(attr.value)) continue;
      const propName = attr.name.name;
      const attrPath = jsxPath.get("openingElement.attributes").find(
        (a) => a.isJSXAttribute() && a.node.name?.name === propName
      );
      if (!attrPath) continue;
      const valuePath = attrPath.get("value.expression");
      if (!valuePath?.node) continue;
      const sourceInfo = analyzeExpression(valuePath, state);
      const arrayContext = getArrayIterationContext(valuePath, state);
      const cacheKey = `${componentAbsPath}::${componentName}::${propName}`;
      PROP_SOURCE_CACHE.set(cacheKey, {
        sourceInfo,
        arrayContext: arrayContext || sourceInfo?.arrayContext,
        fromFile: state.filename
      });
    }
  }
  function lookupCrossFilePropSource(propName, componentName, state) {
    const currentFile = state.filename || state.file?.opts?.filename;
    if (!currentFile) return null;
    const cacheKey = `${currentFile}::${componentName}::${propName}`;
    const cached = PROP_SOURCE_CACHE.get(cacheKey);
    if (cached && cached.sourceInfo) {
      return cached.sourceInfo;
    }
    return lazyEvaluatePropSource(propName, componentName, currentFile);
  }
  function lazyEvaluatePropSource(propName, componentName, componentFile) {
    const traverse = require("@babel/traverse").default;
    for (const [absPath, cached] of FILE_AST_CACHE) {
      if (absPath === componentFile) continue;
      const ast = cached.ast;
      if (!ast) continue;
      let result = null;
      traverse(ast, {
        ImportDeclaration(importPath) {
          if (result) return;
          const source = importPath.node.source.value;
          const resolvedPath = resolveImportPath(source, absPath);
          if (resolvedPath !== componentFile) return;
          let localName = null;
          for (const spec of importPath.node.specifiers) {
            if (t.isImportSpecifier(spec) && spec.imported.name === componentName) {
              localName = spec.local.name;
            } else if (t.isImportDefaultSpecifier(spec)) {
              localName = spec.local.name;
            }
          }
          if (!localName) return;
          const traverseRoot = importPath.parentPath?.parentPath || importPath.parentPath;
          if (!traverseRoot) return;
          traverseRoot.traverse({
            JSXOpeningElement(jsxPath) {
              if (result) return;
              const elemName = getJSXElementName(jsxPath.node);
              if (elemName !== localName) return;
              for (const attr of jsxPath.node.attributes || []) {
                if (!t.isJSXAttribute(attr)) continue;
                if (!t.isJSXIdentifier(attr.name) || attr.name.name !== propName) continue;
                if (!t.isJSXExpressionContainer(attr.value)) continue;
                const attrPath = jsxPath.get("attributes").find(
                  (a) => a.isJSXAttribute() && a.node.name?.name === propName
                );
                if (attrPath) {
                  const valuePath = attrPath.get("value.expression");
                  if (valuePath?.node) {
                    const mockState = { filename: absPath };
                    result = analyzeExpression(valuePath, mockState);
                    const cacheKey = `${componentFile}::${componentName}::${propName}`;
                    PROP_SOURCE_CACHE.set(cacheKey, {
                      sourceInfo: result,
                      arrayContext: result?.arrayContext,
                      fromFile: absPath
                    });
                  }
                }
              }
            }
          });
        }
      });
      if (result) return result;
    }
    return null;
  }
  return {
    tracePropToSource,
    recordPropSources,
    lookupCrossFilePropSource,
    lazyEvaluatePropSource
  };
}

// src/babel-plugin/analysis/dynamic-detector.ts
function createDynamicDetector(t) {
  const parser = require("@babel/parser");
  const traverse = require("@babel/traverse").default;
  function isJSXDynamic(jsxPath) {
    return !!jsxPath.findParent((path4) => {
      if (!path4.isArrowFunctionExpression() && !path4.isFunctionExpression()) {
        return false;
      }
      const parentCall = path4.parentPath;
      if (!parentCall || !parentCall.isCallExpression()) {
        return false;
      }
      const { callee } = parentCall.node;
      if (!t.isMemberExpression(callee) || !t.isIdentifier(callee.property)) {
        return false;
      }
      return ARRAY_METHODS.has(callee.property.name);
    });
  }
  function hasAnyExpression(jsxElement) {
    const openingEl = jsxElement.openingElement;
    if (openingEl?.attributes?.some((attr) => t.isJSXSpreadAttribute(attr))) {
      return true;
    }
    for (const child of jsxElement.children) {
      if (t.isJSXExpressionContainer(child) && !t.isJSXEmptyExpression(child.expression)) {
        return true;
      }
      if (t.isJSXSpreadChild(child)) {
        return true;
      }
    }
    return false;
  }
  function pathHasDynamicJSX(targetPath) {
    if (!targetPath || !targetPath.node) return false;
    let dynamic = false;
    targetPath.traverse({
      JSXExpressionContainer(p) {
        if (dynamic) return;
        if (!t.isJSXEmptyExpression(p.node.expression)) {
          dynamic = true;
          p.stop();
        }
      },
      JSXSpreadAttribute(p) {
        if (dynamic) return;
        dynamic = true;
        p.stop();
      },
      JSXSpreadChild(p) {
        if (dynamic) return;
        dynamic = true;
        p.stop();
      }
    });
    return dynamic;
  }
  function pathIsDynamicComponent(path4, visited = /* @__PURE__ */ new WeakSet()) {
    if (!path4 || !path4.node) return false;
    if (visited.has(path4.node)) return false;
    visited.add(path4.node);
    if (path4.isFunctionDeclaration() || path4.isFunctionExpression() || path4.isArrowFunctionExpression()) {
      return pathHasDynamicJSX(path4);
    }
    if (path4.isVariableDeclarator()) {
      const init = path4.get("init");
      return init && init.node ? pathIsDynamicComponent(init, visited) : false;
    }
    if (path4.isIdentifier()) {
      const binding = path4.scope.getBinding(path4.node.name);
      if (binding) {
        return pathIsDynamicComponent(binding.path, visited);
      }
      return false;
    }
    if (path4.isCallExpression()) {
      const args = path4.get("arguments") || [];
      if (args.length === 0) {
        return true;
      }
      for (const arg of args) {
        if (pathIsDynamicComponent(arg, visited)) {
          return true;
        }
      }
      return false;
    }
    if (path4.isReturnStatement()) {
      const argument = path4.get("argument");
      return argument && argument.node ? pathIsDynamicComponent(argument, visited) : false;
    }
    if (path4.isExpressionStatement()) {
      const expr = path4.get("expression");
      return expr && expr.node ? pathIsDynamicComponent(expr, visited) : false;
    }
    if (path4.isJSXElement() || path4.isJSXFragment()) {
      return pathHasDynamicJSX(path4);
    }
    if (path4.isObjectExpression()) {
      return true;
    }
    return false;
  }
  function fileExportIsDynamic({ absPath, exportName }) {
    if (!absPath) return false;
    const cacheKey = `${absPath}::${exportName}`;
    if (DYNAMIC_COMP_CACHE.has(cacheKey)) {
      return DYNAMIC_COMP_CACHE.get(cacheKey) ?? false;
    }
    DYNAMIC_COMP_CACHE.set(cacheKey, false);
    const ast = parseFileAst(absPath, parser);
    if (!ast) {
      DYNAMIC_COMP_CACHE.set(cacheKey, false);
      return false;
    }
    let dynamic = false;
    const visited = /* @__PURE__ */ new WeakSet();
    function evaluatePath(nodePath) {
      if (!nodePath || !nodePath.node || dynamic) return;
      if (visited.has(nodePath.node)) return;
      visited.add(nodePath.node);
      if (nodePath.isFunctionDeclaration() || nodePath.isFunctionExpression() || nodePath.isArrowFunctionExpression()) {
        if (pathHasDynamicJSX(nodePath)) {
          dynamic = true;
        }
        return;
      }
      if (nodePath.isVariableDeclarator()) {
        evaluatePath(nodePath.get("init"));
        return;
      }
      if (nodePath.isIdentifier()) {
        const binding = nodePath.scope.getBinding(nodePath.node.name);
        if (binding) {
          evaluatePath(binding.path);
        }
        return;
      }
      if (nodePath.isCallExpression()) {
        const args = nodePath.get("arguments") || [];
        if (args.length === 0) {
          dynamic = true;
          return;
        }
        for (const arg of args) {
          evaluatePath(arg);
          if (dynamic) return;
        }
        return;
      }
      if (nodePath.isReturnStatement()) {
        evaluatePath(nodePath.get("argument"));
        return;
      }
      if (nodePath.isExpressionStatement()) {
        evaluatePath(nodePath.get("expression"));
        return;
      }
      if (nodePath.isJSXElement() || nodePath.isJSXFragment()) {
        if (pathHasDynamicJSX(nodePath)) {
          dynamic = true;
        }
        return;
      }
      if (nodePath.isObjectExpression()) {
        dynamic = true;
      }
    }
    traverse(ast, {
      ExportDefaultDeclaration(p) {
        if (dynamic || exportName !== "default") return;
        evaluatePath(p.get("declaration"));
      },
      ExportNamedDeclaration(p) {
        if (dynamic || exportName === "default") return;
        if (p.node.declaration) {
          const decl = p.node.declaration;
          if (t.isFunctionDeclaration(decl) && decl.id?.name === exportName) {
            evaluatePath(p.get("declaration"));
            return;
          }
          if (t.isVariableDeclaration(decl)) {
            decl.declarations.forEach((vd, i) => {
              if (t.isIdentifier(vd.id) && vd.id.name === exportName) {
                evaluatePath(p.get(`declaration.declarations.${i}`));
              }
            });
            return;
          }
        }
        p.node.specifiers.forEach((s) => {
          if (!t.isExportSpecifier(s) || !t.isIdentifier(s.exported) || s.exported.name !== exportName) {
            return;
          }
          if (p.node.source) {
            const from = p.node.source.value;
            const resolved = resolveImportPath(from, absPath);
            if (resolved) {
              if (fileExportIsDynamic({
                absPath: resolved,
                exportName: t.isIdentifier(s.local) ? s.local.name : exportName
              })) {
                dynamic = true;
              }
            }
            return;
          }
          if (t.isIdentifier(s.local)) {
            const binding = p.scope.getBinding(s.local.name);
            if (binding) {
              evaluatePath(binding.path);
            }
          }
        });
      }
    });
    DYNAMIC_COMP_CACHE.set(cacheKey, dynamic);
    return dynamic;
  }
  function componentBindingIsDynamic({ binding, state }) {
    if (!binding || !binding.path) return false;
    const bindingPath = binding.path;
    if (BINDING_DYNAMIC_CACHE.has(bindingPath.node)) {
      return BINDING_DYNAMIC_CACHE.get(bindingPath.node) ?? false;
    }
    let result = false;
    if (bindingPath.isImportSpecifier()) {
      const from = bindingPath.parent.source.value;
      const fileFrom = state.filename || state.file?.opts?.filename || state.file?.sourceFileName || __filename;
      const absPath = resolveImportPath(from, fileFrom);
      const exportName = bindingPath.node.imported.name;
      result = !!absPath ? fileExportIsDynamic({ absPath, exportName }) : false;
      BINDING_DYNAMIC_CACHE.set(bindingPath.node, result);
      return result;
    }
    if (bindingPath.isImportDefaultSpecifier()) {
      const from = bindingPath.parent.source.value;
      const fileFrom = state.filename || state.file?.opts?.filename || state.file?.sourceFileName || __filename;
      const absPath = resolveImportPath(from, fileFrom);
      result = !!absPath ? fileExportIsDynamic({ absPath, exportName: "default" }) : false;
      BINDING_DYNAMIC_CACHE.set(bindingPath.node, result);
      return result;
    }
    if (bindingPath.isImportNamespaceSpecifier()) {
      BINDING_DYNAMIC_CACHE.set(bindingPath.node, false);
      return false;
    }
    result = pathIsDynamicComponent(bindingPath);
    BINDING_DYNAMIC_CACHE.set(bindingPath.node, result);
    return result;
  }
  return {
    isJSXDynamic,
    hasAnyExpression,
    pathHasDynamicJSX,
    pathIsDynamicComponent,
    fileExportIsDynamic,
    componentBindingIsDynamic
  };
}

// src/babel-plugin/analysis/portal-detector.ts
function fileExportHasPortals({
  absPath,
  exportName,
  t,
  traverse,
  parser,
  depth = 0,
  maxDepth = 3
}) {
  if (!absPath || depth > maxDepth) return false;
  const cacheKey = `${absPath}::${exportName}`;
  if (PORTAL_COMP_CACHE.has(cacheKey)) return PORTAL_COMP_CACHE.get(cacheKey);
  const ast = parseFileAst(absPath, parser);
  if (!ast) {
    PORTAL_COMP_CACHE.set(cacheKey, false);
    return false;
  }
  const importMap = /* @__PURE__ */ new Map();
  traverse(ast, {
    ImportDeclaration(p) {
      const src = p.node.source.value;
      const target = resolveImportPath(src, absPath);
      if (!target) return;
      p.node.specifiers.forEach((s) => {
        if (t.isImportSpecifier(s)) {
          importMap.set(s.local.name, {
            absPath: target,
            importName: s.imported.name
          });
        } else if (t.isImportDefaultSpecifier(s)) {
          importMap.set(s.local.name, {
            absPath: target,
            importName: "default"
          });
        }
      });
    }
  });
  let compPaths = [];
  traverse(ast, {
    ExportDefaultDeclaration(p) {
      if (exportName !== "default") return;
      const decl = p.node.declaration;
      if (t.isFunctionDeclaration(decl) || t.isArrowFunctionExpression(decl) || t.isFunctionExpression(decl)) {
        compPaths.push(p.get("declaration"));
      } else if (t.isIdentifier(decl)) {
        const bind = p.scope.getBinding(decl.name);
        if (bind) compPaths.push(bind.path);
      }
    },
    ExportNamedDeclaration(p) {
      if (exportName === "default") return;
      if (p.node.declaration) {
        const d = p.node.declaration;
        if (t.isFunctionDeclaration(d) && d.id?.name === exportName) {
          compPaths.push(p.get("declaration"));
        }
        if (t.isVariableDeclaration(d)) {
          d.declarations.forEach((vd, i) => {
            if (t.isIdentifier(vd.id) && vd.id.name === exportName) {
              compPaths.push(p.get(`declaration.declarations.${i}.init`));
            }
          });
        }
      } else {
        p.node.specifiers.forEach((s) => {
          if (t.isExportSpecifier(s) && t.isIdentifier(s.exported) && s.exported.name === exportName && t.isIdentifier(s.local)) {
            const bind = p.scope.getBinding(s.local.name);
            if (bind) compPaths.push(bind.path);
          }
        });
      }
    }
  });
  if (compPaths.length === 0) {
    PORTAL_COMP_CACHE.set(cacheKey, false);
    return false;
  }
  let found = false;
  const visitedPaths = /* @__PURE__ */ new WeakSet();
  function subtreeHasPortals(nodePath) {
    if (!nodePath || !nodePath.node) return false;
    if (visitedPaths.has(nodePath.node)) return false;
    visitedPaths.add(nodePath.node);
    let hit = false;
    nodePath.traverse({
      JSXOpeningElement(op) {
        if (hit) return;
        const name = jsxNameOf(op.node, t);
        if (isPortalishName(name)) {
          hit = true;
          return;
        }
        if (/^[A-Z]/.test(name || "")) {
          const binding = op.scope.getBinding(name);
          if (binding && binding.path) {
            const childHas = subtreeHasPortals(binding.path);
            if (childHas) {
              hit = true;
              return;
            }
          } else if (importMap.has(name)) {
            const { absPath: childPath, importName } = importMap.get(name);
            const childHas = fileExportHasPortals({
              absPath: childPath,
              exportName: importName,
              t,
              traverse,
              parser,
              depth: depth + 1
            });
            if (childHas) {
              hit = true;
              return;
            }
          }
        }
      }
    });
    return hit;
  }
  for (const pth of compPaths) {
    if (!pth || !pth.node) continue;
    if (subtreeHasPortals(pth)) {
      found = true;
      break;
    }
  }
  PORTAL_COMP_CACHE.set(cacheKey, found);
  return found;
}
function usageIsCompositePortal({
  elementName,
  jsxPath,
  state,
  t,
  traverse,
  parser
}) {
  const binding = jsxPath.scope.getBinding(elementName);
  if (binding && binding.path) {
    let hit = false;
    const portalVisitors = {
      JSXOpeningElement(op) {
        if (hit) return;
        const name = jsxNameOf(op.node, t);
        if (isPortalishName(name)) {
          hit = true;
          return;
        }
        if (/^[A-Z]/.test(name || "")) {
          const innerBinding = op.scope.getBinding(name);
          if (innerBinding && innerBinding.path) {
            innerBinding.path.traverse(portalVisitors);
          }
        }
      }
    };
    binding.path.traverse(portalVisitors);
    if (hit) return true;
  }
  if (binding && binding.path && binding.path.isImportSpecifier()) {
    const from = binding.path.parent.source.value;
    const fileFrom = state.filename || state.file?.opts?.filename || state.file?.sourceFileName || __filename;
    const absPath = resolveImportPath(from, fileFrom);
    if (!absPath) return false;
    const exportName = binding.path.node.imported.name;
    return fileExportHasPortals({
      absPath,
      exportName,
      t,
      traverse,
      parser
    });
  }
  if (binding && binding.path && binding.path.isImportDefaultSpecifier()) {
    const from = binding.path.parent.source.value;
    const fileFrom = state.filename || state.file?.opts?.filename || state.file?.sourceFileName || __filename;
    const absPath = resolveImportPath(from, fileFrom);
    if (!absPath) return false;
    return fileExportHasPortals({
      absPath,
      exportName: "default",
      t,
      traverse,
      parser
    });
  }
  return false;
}

// src/babel-plugin/visitors/jsx-element-visitor.ts
var import_path2 = __toESM(require("path"));
function createJSXElementVisitor(t, deps) {
  const {
    fileNameCache,
    getName,
    hasProp,
    isPortalPrimitive,
    isDirectChildOfAsChildOrTrigger,
    pushMetaAttrs,
    isJSXDynamic,
    hasAnyExpression,
    componentBindingIsDynamic,
    analyzeExpression,
    getArrayIterationContext,
    recordPropSources,
    usageIsCompositePortal: usageIsCompositePortal2,
    traverse,
    parser
  } = deps;
  return function JSXElementVisitor(jsxPath, state) {
    const openingElement = jsxPath.node.openingElement;
    if (!openingElement?.name) return;
    const elementName = getName(openingElement);
    if (!elementName) return;
    if (!/^[A-Z]/.test(elementName)) {
      if (hasProp(openingElement, ATTRS.EXCLUDED)) {
        return;
      }
      const hasDynamicExprChildren = hasAnyExpression(jsxPath.node);
      if (hasDynamicExprChildren) {
        const filename2 = state.filename || state.file?.opts?.filename || state.file?.sourceFileName || "unknown";
        const lineNumber2 = openingElement.loc?.start.line || 0;
        const column2 = openingElement.loc?.start.column || 0;
        if (!fileNameCache.has(filename2)) {
          fileNameCache.set(filename2, import_path2.default.basename(filename2).replace(/\.[jt]sx?$/, ""));
        }
        const normalizedPath2 = fileNameCache.get(filename2) || "unknown";
        const isDynamic2 = true;
        let sourceInfo2 = null;
        let arrayContext2 = null;
        const children = jsxPath.node.children || [];
        for (let i = 0; i < children.length; i++) {
          const child = children[i];
          if (t.isJSXExpressionContainer(child) && !t.isJSXEmptyExpression(child.expression)) {
            const exprContainerPath = jsxPath.get(`children.${i}`);
            if (exprContainerPath && exprContainerPath.node) {
              const exprPath = exprContainerPath.get("expression");
              if (exprPath && exprPath.node) {
                try {
                  sourceInfo2 = analyzeExpression(exprPath, state);
                  if (sourceInfo2 && sourceInfo2.arrayContext) {
                    arrayContext2 = sourceInfo2.arrayContext;
                  }
                } catch (_e) {
                }
              }
            }
            break;
          }
        }
        if (!sourceInfo2) {
          const iterContext = getArrayIterationContext(jsxPath, state);
          if (iterContext) {
            arrayContext2 = iterContext;
            sourceInfo2 = {
              type: iterContext.isEditable ? SOURCE_TYPE.STATIC_IMPORTED : SOURCE_TYPE.EXTERNAL,
              varName: iterContext.arrayVar,
              file: iterContext.arrayFile,
              absFile: iterContext.absFile,
              line: iterContext.arrayLine,
              isEditable: iterContext.isEditable
            };
          }
        }
        pushMetaAttrs(openingElement, {
          normalizedPath: normalizedPath2,
          lineNumber: lineNumber2,
          column: column2,
          elementName,
          isDynamic: isDynamic2,
          sourceInfo: sourceInfo2,
          arrayContext: arrayContext2
        });
        const hasStaticText = children.some((child) => t.isJSXText(child) && child.value.trim());
        if (hasStaticText) {
          const nextChildren = children.map((child, childIndex) => {
            if (t.isJSXExpressionContainer(child) && !t.isJSXEmptyExpression(child.expression)) {
              let wrapperSourceInfo = null;
              let wrapperArrayContext = null;
              try {
                const exprContainerPath = jsxPath.get(`children.${childIndex}`);
                if (exprContainerPath && exprContainerPath.node) {
                  const exprPath = exprContainerPath.get("expression");
                  if (exprPath && exprPath.node) {
                    wrapperSourceInfo = analyzeExpression(exprPath, state);
                    if (wrapperSourceInfo && wrapperSourceInfo.arrayContext) {
                      wrapperArrayContext = wrapperSourceInfo.arrayContext;
                    }
                  }
                }
              } catch (_e) {
              }
              if (!wrapperSourceInfo) {
                const iterContext = getArrayIterationContext(jsxPath, state);
                if (iterContext) {
                  wrapperArrayContext = iterContext;
                  wrapperSourceInfo = {
                    type: iterContext.isEditable ? SOURCE_TYPE.STATIC_IMPORTED : SOURCE_TYPE.EXTERNAL,
                    varName: iterContext.arrayVar,
                    file: iterContext.arrayFile,
                    absFile: iterContext.absFile,
                    line: iterContext.arrayLine,
                    isEditable: iterContext.isEditable
                  };
                }
              }
              const attributes = [
                t.jsxAttribute(t.jsxIdentifier(ATTRS.VE_DYNAMIC), t.stringLiteral("true")),
                t.jsxAttribute(t.jsxIdentifier(ATTRS.EXCLUDED), t.stringLiteral("true")),
                t.jsxAttribute(
                  t.jsxIdentifier("style"),
                  t.jsxExpressionContainer(
                    t.objectExpression([
                      t.objectProperty(t.identifier("display"), t.stringLiteral("contents"))
                    ])
                  )
                )
              ];
              if (wrapperSourceInfo) {
                attributes.push(
                  t.jsxAttribute(t.jsxIdentifier(ATTRS.FILE_NAME), t.stringLiteral(normalizedPath2)),
                  t.jsxAttribute(t.jsxIdentifier(ATTRS.LINE_NUMBER), t.stringLiteral(String(lineNumber2))),
                  t.jsxAttribute(t.jsxIdentifier(ATTRS.COLUMN), t.stringLiteral(String(column2))),
                  t.jsxAttribute(t.jsxIdentifier(ATTRS.COMPONENT), t.stringLiteral(elementName)),
                  t.jsxAttribute(t.jsxIdentifier(ATTRS.ID), t.stringLiteral(`${normalizedPath2}_${lineNumber2}_${column2}_expr${childIndex}`)),
                  t.jsxAttribute(t.jsxIdentifier(ATTRS.DYNAMIC), t.stringLiteral("true"))
                );
                if (wrapperSourceInfo.type) {
                  attributes.push(
                    t.jsxAttribute(t.jsxIdentifier(ATTRS.SOURCE_TYPE), t.stringLiteral(wrapperSourceInfo.type))
                  );
                }
                if (wrapperSourceInfo.varName) {
                  attributes.push(
                    t.jsxAttribute(t.jsxIdentifier(ATTRS.SOURCE_VAR), t.stringLiteral(wrapperSourceInfo.varName))
                  );
                }
                if (wrapperSourceInfo.file) {
                  attributes.push(
                    t.jsxAttribute(t.jsxIdentifier(ATTRS.SOURCE_FILE), t.stringLiteral(wrapperSourceInfo.file))
                  );
                }
                if (wrapperSourceInfo.absFile) {
                  attributes.push(
                    t.jsxAttribute(t.jsxIdentifier(ATTRS.SOURCE_FILE_ABS), t.stringLiteral(wrapperSourceInfo.absFile))
                  );
                }
                if (wrapperSourceInfo.line) {
                  attributes.push(
                    t.jsxAttribute(t.jsxIdentifier(ATTRS.SOURCE_LINE), t.stringLiteral(String(wrapperSourceInfo.line)))
                  );
                }
                if (wrapperSourceInfo.path) {
                  attributes.push(
                    t.jsxAttribute(t.jsxIdentifier(ATTRS.SOURCE_PATH), t.stringLiteral(wrapperSourceInfo.path))
                  );
                }
                attributes.push(
                  t.jsxAttribute(
                    t.jsxIdentifier(ATTRS.SOURCE_EDITABLE),
                    t.stringLiteral(wrapperSourceInfo.isEditable ? "true" : "false")
                  )
                );
                if (wrapperArrayContext) {
                  if (wrapperArrayContext.arrayVar) {
                    attributes.push(
                      t.jsxAttribute(t.jsxIdentifier(ATTRS.ARRAY_VAR), t.stringLiteral(wrapperArrayContext.arrayVar))
                    );
                  }
                  if (wrapperArrayContext.arrayFile) {
                    attributes.push(
                      t.jsxAttribute(t.jsxIdentifier(ATTRS.ARRAY_FILE), t.stringLiteral(wrapperArrayContext.arrayFile))
                    );
                  }
                  if (wrapperArrayContext.arrayLine) {
                    attributes.push(
                      t.jsxAttribute(t.jsxIdentifier(ATTRS.ARRAY_LINE), t.stringLiteral(String(wrapperArrayContext.arrayLine)))
                    );
                  }
                  if (wrapperArrayContext.itemParam) {
                    attributes.push(
                      t.jsxAttribute(t.jsxIdentifier(ATTRS.ARRAY_ITEM_PARAM), t.stringLiteral(wrapperArrayContext.itemParam))
                    );
                  }
                }
              }
              return t.jsxElement(
                t.jsxOpeningElement(t.jsxIdentifier("span"), attributes, false),
                t.jsxClosingElement(t.jsxIdentifier("span")),
                [child],
                false
              );
            }
            return child;
          });
          jsxPath.node.children = nextChildren;
        }
      }
      return;
    }
    if (EXCLUDED_COMPONENTS.has(elementName)) return;
    const parent = jsxPath.parentPath;
    if (parent?.isJSXElement?.()) {
      const parentName = getName(parent.node.openingElement) || "";
      if ([
        "Routes",
        "Switch",
        "BrowserRouter",
        "Router",
        "MemoryRouter",
        "HashRouter"
      ].includes(parentName) || RADIX_ROOTS.has(parentName)) {
        return;
      }
    }
    recordPropSources(elementName, jsxPath, state);
    const filename = state.filename || state.file?.opts?.filename || state.file?.sourceFileName || "unknown";
    const lineNumber = openingElement.loc?.start.line || 0;
    const column = openingElement.loc?.start.column || 0;
    if (!fileNameCache.has(filename)) {
      const base = import_path2.default.basename(filename).replace(/\.[jt]sx?$/, "");
      fileNameCache.set(filename, base);
    }
    const normalizedPath = fileNameCache.get(filename) || "unknown";
    const isInArrayMethod = isJSXDynamic(jsxPath);
    const hasExpressions = hasAnyExpression(jsxPath.node);
    let isDynamic = hasExpressions || isInArrayMethod;
    if (!isDynamic) {
      const hasStaticTextChildren = jsxPath.node.children.some(
        (child) => t.isJSXText(child) && child.value.trim()
      );
      if (!hasStaticTextChildren) {
        const binding = jsxPath.scope.getBinding(elementName);
        if (binding) {
          isDynamic = componentBindingIsDynamic({ binding, state });
        }
      }
    }
    let sourceInfo = null;
    let arrayContext = null;
    if (isDynamic || isInArrayMethod) {
      const children = jsxPath.node.children || [];
      for (let i = 0; i < children.length; i++) {
        const child = children[i];
        if (t.isJSXExpressionContainer(child) && !t.isJSXEmptyExpression(child.expression)) {
          const exprContainerPath = jsxPath.get(`children.${i}`);
          if (exprContainerPath && exprContainerPath.node) {
            const exprPath = exprContainerPath.get("expression");
            if (exprPath && exprPath.node) {
              sourceInfo = analyzeExpression(exprPath, state);
              if (sourceInfo && sourceInfo.arrayContext) {
                arrayContext = sourceInfo.arrayContext;
              }
            }
          }
          break;
        }
      }
      if (!sourceInfo) {
        const iterContext = getArrayIterationContext(jsxPath, state);
        if (iterContext) {
          arrayContext = iterContext;
          sourceInfo = {
            type: iterContext.isEditable ? SOURCE_TYPE.STATIC_IMPORTED : SOURCE_TYPE.EXTERNAL,
            varName: iterContext.arrayVar,
            file: iterContext.arrayFile,
            absFile: iterContext.absFile,
            line: iterContext.arrayLine,
            isEditable: iterContext.isEditable
          };
        }
      }
    }
    const parentIsCompositePortal = (() => {
      const p = jsxPath.parentPath;
      if (!p || !p.isJSXElement || !p.isJSXElement()) return false;
      const parentName = getName(p.node.openingElement);
      if (!parentName || !/^[A-Z]/.test(parentName)) return false;
      return usageIsCompositePortal2({
        elementName: parentName,
        jsxPath: p,
        state,
        t,
        traverse,
        parser,
        RADIX_ROOTS
      });
    })();
    if (hasProp(openingElement, "asChild") || isPortalPrimitive(elementName) || RADIX_ROOTS.has(elementName) || isDirectChildOfAsChildOrTrigger(jsxPath) || parentIsCompositePortal) {
      pushMetaAttrs(
        openingElement,
        { normalizedPath, lineNumber, column, elementName, isDynamic, sourceInfo, arrayContext },
        { markExcluded: true }
      );
      return;
    }
    const compositePortal = usageIsCompositePortal2({
      elementName,
      jsxPath,
      state,
      t,
      traverse,
      parser,
      RADIX_ROOTS
    });
    if (compositePortal) {
      pushMetaAttrs(
        openingElement,
        { normalizedPath, lineNumber, column, elementName, isDynamic, sourceInfo, arrayContext },
        { markExcluded: true }
      );
      return;
    }
    pushMetaAttrs(
      openingElement,
      { normalizedPath, lineNumber, column, elementName, isDynamic, sourceInfo, arrayContext }
    );
  };
}

// src/babel-plugin/visitors/jsx-opening-element-visitor.ts
var import_path3 = __toESM(require("path"));
function createJSXOpeningElementVisitor(t, deps) {
  const {
    fileNameCache,
    insertMetaAttributes,
    isJSXDynamic,
    hasAnyExpression,
    analyzeExpression,
    getArrayIterationContext
  } = deps;
  return function JSXOpeningElementVisitor(jsxPath, state) {
    const nameNode = jsxPath.node.name;
    if (!nameNode) return;
    let elementName;
    if (t.isJSXIdentifier(nameNode)) {
      elementName = nameNode.name;
    } else if (t.isJSXMemberExpression(nameNode)) {
      elementName = nameNode.property.name;
    } else {
      return;
    }
    if (elementName === "Fragment") {
      return;
    }
    if (/^[A-Z]/.test(elementName)) {
      return;
    }
    const hasDebugAttr = jsxPath.node.attributes.some(
      (attr) => t.isJSXAttribute(attr) && attr.name && attr.name.name && attr.name.name.startsWith("x-")
    );
    if (hasDebugAttr) return;
    const filename = state.filename || state.file?.opts?.filename || state.file?.sourceFileName || "unknown";
    const lineNumber = jsxPath.node.loc?.start.line || 0;
    const column = jsxPath.node.loc?.start.column || 0;
    if (!fileNameCache.has(filename)) {
      const base = import_path3.default.basename(filename).replace(/\.[jt]sx?$/, "");
      fileNameCache.set(filename, base);
    }
    const normalizedPath = fileNameCache.get(filename) || "unknown";
    const parentElement = jsxPath.parentPath;
    const isInArrayMethod = parentElement ? isJSXDynamic(parentElement) : false;
    const hasExpressions = parentElement && parentElement.node ? hasAnyExpression(parentElement.node) : false;
    const needsSourceAnalysis = hasExpressions;
    const isDynamic = hasExpressions;
    let sourceInfo = null;
    let arrayContext = null;
    if (needsSourceAnalysis && parentElement && parentElement.node) {
      const children = parentElement.node.children || [];
      for (let i = 0; i < children.length; i++) {
        const child = children[i];
        if (t.isJSXExpressionContainer(child) && !t.isJSXEmptyExpression(child.expression)) {
          const exprContainerPath = parentElement.get(`children.${i}`);
          if (exprContainerPath && exprContainerPath.node) {
            const exprPath = exprContainerPath.get("expression");
            if (exprPath && exprPath.node) {
              sourceInfo = analyzeExpression(exprPath, state);
              if (sourceInfo && sourceInfo.arrayContext) {
                arrayContext = sourceInfo.arrayContext;
              }
            }
          }
          break;
        }
      }
      if (!sourceInfo) {
        const iterContext = getArrayIterationContext(parentElement, state);
        if (iterContext) {
          arrayContext = iterContext;
          sourceInfo = {
            type: iterContext.isEditable ? SOURCE_TYPE.STATIC_IMPORTED : SOURCE_TYPE.EXTERNAL,
            varName: iterContext.arrayVar,
            file: iterContext.arrayFile,
            absFile: iterContext.absFile,
            line: iterContext.arrayLine,
            isEditable: iterContext.isEditable
          };
        }
      }
    }
    const metaAttrs = [
      t.jsxAttribute(
        t.jsxIdentifier(ATTRS.FILE_NAME),
        t.stringLiteral(normalizedPath)
      ),
      t.jsxAttribute(
        t.jsxIdentifier(ATTRS.LINE_NUMBER),
        t.stringLiteral(String(lineNumber))
      ),
      t.jsxAttribute(
        t.jsxIdentifier(ATTRS.COLUMN),
        t.stringLiteral(String(column))
      ),
      t.jsxAttribute(
        t.jsxIdentifier(ATTRS.COMPONENT),
        t.stringLiteral(elementName)
      ),
      t.jsxAttribute(
        t.jsxIdentifier(ATTRS.ID),
        t.stringLiteral(`${normalizedPath}_${lineNumber}_${column}`)
      ),
      t.jsxAttribute(
        t.jsxIdentifier(ATTRS.DYNAMIC),
        t.stringLiteral(isDynamic ? "true" : "false")
      )
    ];
    if (sourceInfo) {
      if (sourceInfo.type) {
        metaAttrs.push(
          t.jsxAttribute(t.jsxIdentifier(ATTRS.SOURCE_TYPE), t.stringLiteral(sourceInfo.type))
        );
      }
      if (sourceInfo.varName) {
        metaAttrs.push(
          t.jsxAttribute(t.jsxIdentifier(ATTRS.SOURCE_VAR), t.stringLiteral(sourceInfo.varName))
        );
      }
      if (sourceInfo.file) {
        metaAttrs.push(
          t.jsxAttribute(t.jsxIdentifier(ATTRS.SOURCE_FILE), t.stringLiteral(sourceInfo.file))
        );
      }
      if (sourceInfo.absFile) {
        metaAttrs.push(
          t.jsxAttribute(t.jsxIdentifier(ATTRS.SOURCE_FILE_ABS), t.stringLiteral(sourceInfo.absFile))
        );
      }
      if (sourceInfo.line) {
        metaAttrs.push(
          t.jsxAttribute(t.jsxIdentifier(ATTRS.SOURCE_LINE), t.stringLiteral(String(sourceInfo.line)))
        );
      }
      if (sourceInfo.path) {
        metaAttrs.push(
          t.jsxAttribute(t.jsxIdentifier(ATTRS.SOURCE_PATH), t.stringLiteral(sourceInfo.path))
        );
      }
      metaAttrs.push(
        t.jsxAttribute(
          t.jsxIdentifier(ATTRS.SOURCE_EDITABLE),
          t.stringLiteral(sourceInfo.isEditable ? "true" : "false")
        )
      );
    }
    if (arrayContext) {
      if (arrayContext.arrayVar) {
        metaAttrs.push(
          t.jsxAttribute(t.jsxIdentifier(ATTRS.ARRAY_VAR), t.stringLiteral(arrayContext.arrayVar))
        );
      }
      if (arrayContext.arrayFile) {
        metaAttrs.push(
          t.jsxAttribute(t.jsxIdentifier(ATTRS.ARRAY_FILE), t.stringLiteral(arrayContext.arrayFile))
        );
      }
      if (arrayContext.arrayLine) {
        metaAttrs.push(
          t.jsxAttribute(t.jsxIdentifier(ATTRS.ARRAY_LINE), t.stringLiteral(String(arrayContext.arrayLine)))
        );
      }
      if (arrayContext.itemParam) {
        metaAttrs.push(
          t.jsxAttribute(t.jsxIdentifier(ATTRS.ARRAY_ITEM_PARAM), t.stringLiteral(arrayContext.itemParam))
        );
      }
    }
    insertMetaAttributes(jsxPath.node, metaAttrs);
  };
}

// src/babel-plugin/index.ts
var babelMetadataPlugin = ({ types: t }) => {
  const fileNameCache = /* @__PURE__ */ new Map();
  const parser = require("@babel/parser");
  const traverse = require("@babel/traverse").default;
  const { findExportedVariableInfo } = createCrossFileResolver(t);
  const jsxUtils = createJsxUtils(t);
  const dynamicDetector = createDynamicDetector(t);
  const expressionAnalyzerRef = {};
  const arrayContextRef = {};
  const arrayContextModule = createArrayContext(t, {
    analyzeIdentifier: (...args) => expressionAnalyzerRef.analyzeIdentifier(...args),
    analyzeMemberExpression: (...args) => expressionAnalyzerRef.analyzeMemberExpression(...args)
  });
  const propSourceTrackerRef = {};
  const expressionAnalyzerModule = createExpressionAnalyzer(t, {
    getArrayIterationContext: (...args) => arrayContextRef.getArrayIterationContext(...args),
    getContainingComponentName: jsxUtils.getContainingComponentName,
    tracePropToSource: (...args) => propSourceTrackerRef.tracePropToSource(...args),
    findExportedVariableInfo
  });
  Object.assign(expressionAnalyzerRef, expressionAnalyzerModule);
  Object.assign(arrayContextRef, arrayContextModule);
  const propSourceTrackerModule = createPropSourceTracker(t, {
    analyzeExpression: expressionAnalyzerModule.analyzeExpression,
    getArrayIterationContext: arrayContextModule.getArrayIterationContext,
    getJSXElementName: jsxUtils.getJSXElementName,
    getContainingComponentName: jsxUtils.getContainingComponentName
  });
  Object.assign(propSourceTrackerRef, propSourceTrackerModule);
  const jsxElementVisitor = createJSXElementVisitor(t, {
    fileNameCache,
    getName: jsxUtils.getName,
    hasProp: jsxUtils.hasProp,
    isPortalPrimitive: jsxUtils.isPortalPrimitive,
    isDirectChildOfAsChildOrTrigger: jsxUtils.isDirectChildOfAsChildOrTrigger,
    pushMetaAttrs: jsxUtils.pushMetaAttrs,
    isJSXDynamic: dynamicDetector.isJSXDynamic,
    hasAnyExpression: dynamicDetector.hasAnyExpression,
    componentBindingIsDynamic: dynamicDetector.componentBindingIsDynamic,
    analyzeExpression: expressionAnalyzerModule.analyzeExpression,
    getArrayIterationContext: arrayContextModule.getArrayIterationContext,
    recordPropSources: propSourceTrackerModule.recordPropSources,
    usageIsCompositePortal,
    traverse,
    parser
  });
  const jsxOpeningElementVisitor = createJSXOpeningElementVisitor(t, {
    fileNameCache,
    insertMetaAttributes: jsxUtils.insertMetaAttributes,
    isJSXDynamic: dynamicDetector.isJSXDynamic,
    hasAnyExpression: dynamicDetector.hasAnyExpression,
    analyzeExpression: expressionAnalyzerModule.analyzeExpression,
    getArrayIterationContext: arrayContextModule.getArrayIterationContext
  });
  return {
    name: "element-metadata-plugin",
    visitor: {
      JSXElement: jsxElementVisitor,
      JSXOpeningElement: jsxOpeningElementVisitor
    }
  };
};
var index_default = babelMetadataPlugin;
