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O,OAC/B,GACA,IAGJ,IAAK,MAAM,KAAU,EAAS,CAC5B,MAAM,MAAE,GAAU,EAElB,IAAI,EAAU,EAEd,MAAM,EAAY,EAAQ,YAAY,KAElC,GAAa,IACf,EAAU,EAAQ,UAAU,EAAG,IAGjC,EAAa,KAAK,EACpB,CAEA,OAAO,CACT","file":"/npm/detective-html@0.1.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/detective-html@0.1.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\n\nconst { debuglog } = require(\"util\");\nconst { parse } = require(\"parse5\");\nconst { traverse, normalizeOptions } = require(\"./utils\");\n\nconst debug = debuglog(\"detective-html\");\n\n/**\n * Extract the names of the used files from a given html file's content\n *\n * @param  {String} fileContent\n * @param  {Object} rawOptions: optional argument. When provided, this object contains\n *                  attributes to track the way webpack does it\n *                  (cf. https://webpack.js.org/loaders/html-loader/#object)\n *                  An example of rawOptions is in test/test-data.js\n * @return {String[]}\n */\nmodule.exports = function detective(fileContent, rawOptions={}) {\n  if (typeof fileContent === \"undefined\") throw new Error(\"content not given\");\n  if (typeof fileContent !== \"string\")\n    throw new Error(\"content is not a string\");\n\n  let dependencies = [];\n  let ast = {};\n\n  // get sourcesOptions, the way webpack does it - cf. https://webpack.js.org/loaders/html-loader/#object\n  let norm = normalizeOptions(rawOptions, {})\n  let sourcesOption = norm.sources.list\n\n  try {\n    debug(\"content: %s\", fileContent);\n    ast = parse(fileContent);\n  } catch (error) {\n    debug(\"parse error: %s\", error.message);\n  }\n\n  detective.ast = ast;\n\n  const sources = [];\n\n  traverse(ast, (node) => {\n    const { tagName, attrs: attributes } = node;\n\n    if (!tagName) {\n      return;\n    }\n\n    attributes.forEach((attribute) => {\n      let { name } = attribute;\n\n      name = attribute.prefix ? `${attribute.prefix}:${name}` : name;\n\n      const handlers = sourcesOption.get(tagName.toLowerCase());\n\n      if (!handlers) {\n        return;\n      }\n\n      if (handlers.size === 0) {\n        return;\n      }\n\n      const handler = handlers.get(name.toLowerCase());\n\n      if (!handler) {\n        return;\n      }\n\n      if (handler.filter && !handler.filter(tagName, name, attributes)) {\n        return;\n      }\n\n      const optionsForTypeFn = {\n        tag: tagName,\n        attributes,\n        attribute: name,\n        attributePrefix: attribute.prefix,\n        attributeNamespace: attribute.namespace,\n        value: attribute.value,\n      };\n\n      let result;\n\n      try {\n        result = handler.type(optionsForTypeFn);\n      } catch (error) {\n        debug(\"handler.type error: %s\", error.message);\n      }\n\n      result = Array.isArray(result) ? result : [result];\n\n      for (const source of result) {\n        if (!source) {\n          continue;\n        }\n\n        sources.push({ value: source.value });\n      }\n    });\n  });\n\n  for (const source of sources) {\n    const { value } = source;\n\n    let request = value;\n\n    const indexHash = request.lastIndexOf(\"#\");\n\n    if (indexHash >= 0) {\n      request = request.substring(0, indexHash);\n    }\n\n    dependencies.push(request);\n  }\n\n  return dependencies;\n};\n"]}