class Metadata {
  constructor(fileURL, modules, components) {
    this.modules = modules;
    this.fileURL = new URL(fileURL);
    this.metadataCache = new Map();
  }
  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;
  }
  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 = specifier.startsWith(".") ? new URL(specifier, this.fileURL).pathname : 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);
}
export {
  createMetadata
};
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vLi4vc3JjL3J1bnRpbWUvc2VydmVyL21ldGFkYXRhLnRzIl0sCiAgIm1hcHBpbmdzIjogIkFBVUEsZUFBZTtBQUFBLEVBR2IsWUFBWSxTQUF3QixTQUF1QixZQUFtQjtBQUExQztBQUNsQyxTQUFLLFVBQVUsSUFBSSxJQUFJO0FBQ3ZCLFNBQUssZ0JBQWdCLElBQUk7QUFBQTtBQUFBLEVBRzNCLFFBQVEsV0FBK0I7QUFDckMsVUFBTSxXQUFXLEtBQUsscUJBQXFCO0FBQzNDLFdBQU8sc0NBQVUsaUJBQWdCO0FBQUE7QUFBQSxFQUduQyxVQUFVLFdBQStCO0FBQ3ZDLFVBQU0sV0FBVyxLQUFLLHFCQUFxQjtBQ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