import path from "path";
import { viteifyURL } from "../util.js";
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 = viteifyURL(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,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vLi4vc3JjL2NvcmUvc3NyL2Nzcy50cyJdLAogICJtYXBwaW5ncyI6ICJBQUVBO0FBQ0E7QUFHTyxNQUFNLG1CQUFtQixJQUFJLElBQUksQ0FBQyxRQUFRLFNBQVMsU0FBUyxTQUFTLFNBQVMsV0FBVztBQUd6Rix5QkFBeUIsVUFBZSxZQUE2QztBQUMxRixRQUFNLE1BQU0sSUFBSTtBQUNoQixRQUFNLEVBQUUsa0JBQWtCLFdBQVc7QUFDckMsUUFBTSxTQUFTLFdBQVc7QUFDMUIsUUFBTSxjQUFjLGNBQWMsSUFBSTtBQUN0QyxNQUFJLENBQUM7QUFBYSxXQUFPO0FBR3pCLG9CQUFrQixhQUFxQixVQUFVLElBQUksT0FBZTtBQUNsRSxVQUFNLGFBQWEsY0FBYyxJQUFJO0FBQ3JDLFFBQUksQ0FBQztBQUFZO0FBQ2pCLGVBQVcsa0JBQWtCLFdBQVcsaUJBQWlCO0FBQ3ZELFVBQUksQ0FBQyxlQUFlLE1BQU0sUUFBUSxJQUFJLGVBQWU7QUFBSztBQUMxRCxZQUFNLE1BQU0sS0FBSyxRQUFRLGVBQWUsR0FBRztBQUMzQyxVQUFJLGlCQUFpQixJQUFJLE1BQU07QUFDN0IsWUFBSSxJQUFJLGVBQWU7QUFBQSxhQUNsQjtBQUNMLGlCQUFTLGVBQWUsSUFBSTtBQUFBO0FBRTlCLGNBQVEsSUFBSSxlQUFlO0FBQUE7QUFBQTtBQUcvQixXQUFTO0FBRVQsU0FBTztBQUFBOyIsCiAgIm5hbWVzIjogW10KfQo=
