import {fileURLToPath} from "url";
import path from "path";
import slash from "slash";
const STYLE_EXTENSIONS = new Set([".css", ".pcss", ".scss", ".sass", ".styl", ".stylus", ".less"]);
function getStylesForURL(filePath, viteServer) {
  const css = new Set();
  const {idToModuleMap} = viteServer.moduleGraph;
  const rootID = slash(fileURLToPath(filePath));
  const moduleGraph = idToModuleMap.get(rootID);
  if (!moduleGraph)
    return css;
  function crawlCSS(entryModule, scanned = new Set()) {
    const moduleName = idToModuleMap.get(entryModule);
    if (!moduleName)
      return;
    for (const importedModule of moduleName.importedModules) {
      if (!importedModule.id || scanned.has(importedModule.id))
        continue;
      const ext = path.extname(importedModule.id.toLowerCase());
      if (STYLE_EXTENSIONS.has(ext)) {
        css.add(importedModule.id);
      } else {
        crawlCSS(importedModule.id, scanned);
      }
      scanned.add(importedModule.id);
    }
  }
  crawlCSS(rootID);
  return css;
}
export {
  STYLE_EXTENSIONS,
  getStylesForURL
};
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vLi4vc3JjL2NvcmUvc3NyL2Nzcy50cyJdLAogICJtYXBwaW5ncyI6ICJBQUVBO0FBQ0E7QUFDQTtBQUdPLE1BQU0sbUJBQW1CLElBQUksSUFBSSxDQUFDLFFBQVEsU0FBUyxTQUFTLFNBQVMsU0FBUyxXQUFXO0FBR3pGLHlCQUF5QixVQUFlLFlBQTZDO0FBQzFGLFFBQU0sTUFBTSxJQUFJO0FBQ2hCLFFBQU0sQ0FBRSxpQkFBa0IsV0FBVztBQUNyQyxRQUFNLFNBQVMsTUFBTSxjQUFjO0FBQ25DLFFBQU0sY0FBYyxjQUFjLElBQUk7QUFDdEMsTUFBSSxDQUFDO0FBQWEsV0FBTztBQUd6QixvQkFBa0IsYUFBcUIsVUFBVSxJQUFJLE9BQWU7QUFDbEUsVUFBTSxhQUFhLGNBQWMsSUFBSTtBQUNyQyxRQUFJLENBQUM7QUFBWTtBQUNqQixlQUFXLGtCQUFrQixXQUFXLGlCQUFpQjtBQUN2RCxVQUFJLENBQUMsZUFBZSxNQUFNLFFBQVEsSUFBSSxlQUFlO0FBQUs7QUFDMUQsWUFBTSxNQUFNLEtBQUssUUFBUSxlQUFlLEdBQUc7QUFDM0MsVUFBSSxpQkFBaUIsSUFBSSxNQUFNO0FBQzdCLFlBQUksSUFBSSxlQUFlO0FBQUEsYUFDbEI7QUFDTCxpQkFBUyxlQUFlLElBQUk7QUFBQTtBQUU5QixjQUFRLElBQUksZUFBZTtBQUFBO0FBQUE7QUFHL0IsV0FBUztBQUVULFNBQU87QUFBQTsiLAogICJuYW1lcyI6IFtdCn0K
