{"version":3,"file":"main.B_fi96.js","sources":["theme-12/virtual:theme","theme-12/discourse/lib/colors.js","theme-12/discourse/initializers/tag-icons.js","theme-12/virtual:entrypoint:main"],"sourcesContent":["import { getObjectForTheme } from \"discourse/lib/theme-settings-store\";\n\nexport const settings = getObjectForTheme(12);\n\nexport function themePrefix(key) {\n  return `theme_translations.12.${key}`;\n}\n","const hexToRgb = (hex) => {\n  if (typeof hex !== \"string\") {\n    throw new TypeError(\"Hex color must be a string\");\n  }\n\n  let value = hex.trim().replace(/^#/, \"\");\n\n  if (value.length === 3) {\n    value = value\n      .split(\"\")\n      .map((char) => char + char)\n      .join(\"\");\n  }\n\n  if (!/^[0-9a-fA-F]{6}$/.test(value)) {\n    return false;\n  }\n\n  const num = parseInt(value, 16);\n\n  // eslint-disable-next-line no-bitwise\n  return [(num >> 16) & 255, (num >> 8) & 255, num & 255];\n};\n\nconst luminance = (rgb) => {\n  const c = [rgb[0], rgb[1], rgb[2]].map((v) => {\n    v /= 255;\n    return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);\n  });\n  return 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];\n};\n\nexport const contrastColor = (hexColor) => {\n  const rgb = hexToRgb(hexColor);\n  if (!rgb) {\n    return \"\";\n  }\n  return luminance(rgb) >= 0.45 ? \"#000d\" : \"#fffd\";\n};\n","import TagHashtagType from \"discourse/lib/hashtag-types/tag\";\nimport { iconHTML } from \"discourse/lib/icon-library\";\nimport { withPluginApi } from \"discourse/lib/plugin-api\";\nimport { defaultRenderTag } from \"discourse/lib/render-tag\";\nimport { contrastColor } from \"../lib/colors\";\n\nfunction iconTagRenderer(tag, params) {\n  // Get the rendered default tag markup.\n  const renderedTag = defaultRenderTag(tag, params);\n\n  // Handle both string tags (legacy) and object tags (new format: { id, name, slug })\n  const tagName = typeof tag === \"string\" ? tag : tag.slug || tag.name;\n\n  // Get the tag configuration list from the settings.\n  const tagIconList = settings.tag_icon_list.split(\"|\");\n\n  // Returns the tag configuration if found.\n  const tagIconItem = tagIconList.find(\n    (line) =>\n      line.indexOf(\",\") > -1 &&\n      tagName.toLowerCase() === line.substr(0, line.indexOf(\",\")).toLowerCase()\n  );\n\n  // Update the tag markup with an SVG icon, and inline-styles for the colors.\n  if (tagIconItem) {\n    const [, iconName, color] = tagIconItem.split(\",\");\n\n    const parser = new DOMParser();\n    const tagElement = parser.parseFromString(renderedTag, \"text/html\").body\n      .firstChild;\n    const iconElement = parser.parseFromString(\n      `<span class=\"tag-icon\">${iconHTML(iconName)}</span>`,\n      \"text/html\"\n    ).body.firstChild;\n\n    tagElement.prepend(iconElement);\n    tagElement.classList.add(\"discourse-tag--tag-icons-style\");\n    tagElement.style.setProperty(\"--color1\", color ?? \"\");\n\n    tagElement.style.setProperty(\"--color2\", color ? contrastColor(color) : \"\");\n\n    return tagElement.outerHTML;\n  }\n\n  return renderedTag;\n}\n\nclass TagHashtagTypeWithIcon extends TagHashtagType {\n  constructor(dict, owner) {\n    super(owner);\n    this.dict = dict;\n  }\n\n  generateIconHTML(hashtag) {\n    const opt = hashtag.slug && this.dict[hashtag.slug];\n    if (opt) {\n      const svgIcon = iconHTML(opt.icon, {\n        class: `hashtag-color--${this.type}-${hashtag.id}`,\n      });\n      const newIcon = document.createElement(\"span\");\n      newIcon.classList.add(\"hashtag-tag-icon\");\n      newIcon.innerHTML = svgIcon;\n      if (opt.color) {\n        newIcon.style.setProperty(\"--color1\", opt.color ?? \"\");\n        newIcon.style.setProperty(\n          \"--color2\",\n          opt.color ? contrastColor(opt.color) : \"\"\n        );\n      }\n      return newIcon.outerHTML;\n    }\n\n    return super.generateIconHTML(hashtag);\n  }\n}\n\nexport default {\n  name: \"tag-icons\",\n\n  before: \"hashtag-css-generator\",\n\n  initialize(owner) {\n    withPluginApi((api) => {\n      api.replaceTagRenderer(iconTagRenderer);\n\n      /** @type {Record<string, { icon: string, color?: string }>} */\n      const tagsMap = {};\n\n      const tagIconList = settings.tag_icon_list.split(\"|\");\n\n      tagIconList.forEach((tagIcon) => {\n        const [tagName, prefixValue, prefixColor] = tagIcon.split(\",\");\n\n        if (tagName && prefixValue) {\n          if (api.registerCustomTagSectionLinkPrefixIcon) {\n            api.registerCustomTagSectionLinkPrefixIcon({\n              tagName,\n              prefixValue,\n              prefixColor,\n            });\n          }\n\n          tagsMap[tagName] = {\n            icon: prefixValue,\n            color: prefixColor,\n          };\n        }\n      });\n\n      if (api.registerHashtagType) {\n        api.registerHashtagType(\n          \"tag\",\n          new TagHashtagTypeWithIcon(tagsMap, owner)\n        );\n      }\n    });\n  },\n};\n","import * as Mod1 from \"./discourse/initializers/tag-icons\";\nimport * as Mod2 from \"./discourse/lib/colors\";\nconst compatModules = {\n  \"discourse/initializers/tag-icons\": Mod1,\n  \"discourse/lib/colors\": Mod2,\n};\nexport { compatModules };\nexport default compatModules;\n"],"names":["settings","getObjectForTheme","contrastColor","hexColor","rgb","hex","TypeError","value","trim","replace","length","split","map","char","join","test","num","parseInt","hexToRgb","c","v","Math","pow","luminance","iconTagRenderer","tag","params","renderedTag","defaultRenderTag","tagName","slug","name","tagIconItem","tag_icon_list","find","line","indexOf","toLowerCase","substr","iconName","color","parser","DOMParser","tagElement","parseFromString","body","firstChild","iconElement","iconHTML","prepend","classList","add","style","setProperty","outerHTML","TagHashtagTypeWithIcon","TagHashtagType","constructor","dict","owner","super","this","generateIconHTML","hashtag","opt","svgIcon","icon","class","type","id","newIcon","document","createElement","innerHTML","tagIcons","before","initialize","withPluginApi","api","replaceTagRenderer","tagsMap","forEach","tagIcon","prefixValue","prefixColor","registerCustomTagSectionLinkPrefixIcon","registerHashtagType","compatModules","Mod2"],"mappings":"0cAEaA,EAAWC,EAAkB;ACF1C,MAgCaC,EAAiBC,IAC5B,MAAMC,EAjCUC,KAChB,GAAmB,iBAARA,EACT,MAAM,IAAIC,UAAU;AAGtB,IAAIC,EAAQF,EAAIG,OAAOC,QAAQ,KAAM;AASrC,GAPqB,IAAjBF,EAAMG,SAC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