class Metadata {
  constructor(fileURL, modules, hydratedComponents, hoisted) {
    this.modules = modules;
    this.hydratedComponents = hydratedComponents;
    this.hoisted = hoisted;
    this.fileURL = new URL(fileURL);
    this.metadataCache = new Map();
  }
  resolvePath(specifier) {
    return specifier.startsWith(".") ? new URL(specifier, this.fileURL).pathname : specifier;
  }
  getPath(Component) {
    const metadata = this.getComponentMetadata(Component);
    return (metadata == null ? void 0 : metadata.componentUrl) || null;
  }
  getExport(Component) {
    const metadata = this.getComponentMetadata(Component);
    return (metadata == null ? void 0 : metadata.componentExport) || null;
  }
  getAllHydratedComponentPaths() {
    const paths = new Set();
    for (const component of this.hydratedComponents) {
      const path = this.getPath(component);
      if (path) {
        paths.add(path);
      }
    }
    for (const {module: mod} of this.modules) {
      if (typeof mod.$$metadata !== "undefined") {
        for (const path of mod.$$metadata.getAllHydratedComponentPaths()) {
          paths.add(path);
        }
      }
    }
    return paths;
  }
  getComponentMetadata(Component) {
    if (this.metadataCache.has(Component)) {
      return this.metadataCache.get(Component);
    }
    const metadata = this.findComponentMetadata(Component);
    this.metadataCache.set(Component, metadata);
    return metadata;
  }
  findComponentMetadata(Component) {
    const isCustomElement = typeof Component === "string";
    for (const {module, specifier} of this.modules) {
      const id = this.resolvePath(specifier);
      for (const [key, value] of Object.entries(module)) {
        if (isCustomElement) {
          if (key === "tagName" && Component === value) {
            return {
              componentExport: key,
              componentUrl: id
            };
          }
        } else if (Component === value) {
          return {
            componentExport: key,
            componentUrl: id
          };
        }
      }
    }
    return null;
  }
}
function createMetadata(fileURL, options) {
  return new Metadata(fileURL, options.modules, options.hydratedComponents, options.hoisted);
}
export {
  Metadata,
  createMetadata
};
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vLi4vc3JjL3J1bnRpbWUvc2VydmVyL21ldGFkYXRhLnRzIl0sCiAgIm1hcHBpbmdzIjogIkFBVU8sZUFBZTtBQUFBLEVBR3BCLFlBQVksU0F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