{"version":3,"file":"virtual_main.js","sources":["theme-15/virtual:init-settings","theme-15/virtual:theme","theme-15/discourse/initializers/theme-field-1065-common-html-script-1.js","theme-15/virtual:main"],"sourcesContent":["import { registerSettings } from \"discourse/lib/theme-settings-store\";\n\nregisterSettings(15, {});\n","import { getObjectForTheme } from \"discourse/lib/theme-settings-store\";\n\nexport const settings = getObjectForTheme(15);\n\nexport function themePrefix(key) {\n  return `theme_translations.15.${key}`;\n}\n","import { withPluginApi } from \"discourse/lib/plugin-api\";\nimport deprecated from \"discourse/lib/deprecated\";\n\nexport default {\n  name: \"theme-field-1065-common-html-script-1\",\n  after: \"inject-objects\",\n\n  initialize() {\n    deprecated(\n      \"Adding JS code using <script type='text/discourse-plugin'> is deprecated. Move this code to a dedicated JavaScript file.\",\n      {\n        id: \"discourse.script-tag-discourse-plugin\",\n        url: \"https://meta.discourse.org/t/366482\",\n      }\n    )\n    withPluginApi(\"1.13.0\", (api) => {\n      \n  (function () {\n    const COMPONENT_ID = \"cado-category-directory\";\n    let renderGeneration = 0;\n\n    function isAnonymousHomepage() {\n      if (api.getCurrentUser()) {\n        return false;\n      }\n\n      const path = window.location.pathname.replace(/\\/$/, \"\");\n      return path === \"\" || path === \"/latest\";\n    }\n\n    function countLabel(count) {\n      const value = count || 0;\n      return `${value} ${value === 1 ? \"question\" : \"questions\"}`;\n    }\n\n    function categoryUrl(category, categoriesById) {\n      const parent = category.parent_category_id\n        ? categoriesById.get(category.parent_category_id)\n        : null;\n\n      if (parent) {\n        return `/c/${parent.slug}/${category.slug}/${category.id}`;\n      }\n\n      return `/c/${category.slug}/${category.id}`;\n    }\n\n    function visibleCategory(category) {\n      return !category.read_restricted && !category.name.startsWith(\"_\");\n    }\n\n    async function renderDirectory(attempt = 0) {\n      const generation = ++renderGeneration;\n      document.querySelectorAll(`#${COMPONENT_ID}`).forEach((element) => element.remove());\n\n      if (!isAnonymousHomepage()) {\n        return;\n      }\n\n      const anchor =\n        document.querySelector(\".list-controls\") ||\n        document.querySelector(\"#list-area\");\n\n      if (!anchor) {\n        if (attempt < 20) {\n          window.setTimeout(() => renderDirectory(attempt + 1), 250);\n        }\n        return;\n      }\n\n      let site;\n      try {\n        const response = await fetch(\"/site.json\", { credentials: \"same-origin\" });\n        if (!response.ok) {\n          return;\n        }\n        site = await response.json();\n      } catch {\n        return;\n      }\n\n      if (generation !== renderGeneration) {\n        return;\n      }\n\n      const categories = (site.categories || []).filter(visibleCategory);\n      const categoriesById = new Map(categories.map((category) => [category.id, category]));\n      const childrenByParent = new Map();\n\n      for (const category of categories) {\n        if (!category.parent_category_id) {\n          continue;\n        }\n\n        if (!childrenByParent.has(category.parent_category_id)) {\n          childrenByParent.set(category.parent_category_id, []);\n        }\n\n        childrenByParent.get(category.parent_category_id).push(category);\n      }\n\n      const topCategories = categories\n        .filter((category) => !category.parent_category_id)\n        .sort((a, b) => (b.topic_count || 0) - (a.topic_count || 0));\n\n      if (!topCategories.length) {\n        return;\n      }\n\n      const wrapper = document.createElement(\"section\");\n      wrapper.id = COMPONENT_ID;\n      wrapper.className = \"cado-category-directory\";\n      wrapper.innerHTML = `\n        <div class=\"cado-category-directory__header\">\n          <div>\n            <h2>Browse CADOverflow Categories</h2>\n            <p>Find SOLIDWORKS API questions by product area, PDM vault workflow, add-ins, macros, and drafting topic.</p>\n          </div>\n          <a class=\"cado-category-directory__all\" href=\"/categories\">All categories</a>\n        </div>\n        <div class=\"cado-category-directory__grid\"></div>\n      `;\n\n      const grid = wrapper.querySelector(\".cado-category-directory__grid\");\n\n      for (const category of topCategories) {\n        const childCategories = (childrenByParent.get(category.id) || []).sort(\n          (a, b) => (b.topic_count || 0) - (a.topic_count || 0)\n        );\n        const card = document.createElement(\"article\");\n        card.className = \"cado-category-card\";\n        card.style.setProperty(\"--category-color\", `#${category.color || \"777\"}`);\n        card.innerHTML = `\n          <a class=\"cado-category-card__main\" href=\"${categoryUrl(category, categoriesById)}\">\n            <span class=\"cado-category-card__swatch\"></span>\n            <span class=\"cado-category-card__name\"></span>\n            <span class=\"cado-category-card__count\">${countLabel(category.topic_count)}</span>\n          </a>\n          <div class=\"cado-category-card__children\"></div>\n        `;\n\n        card.querySelector(\".cado-category-card__name\").textContent = category.name;\n\n        const childrenElement = card.querySelector(\".cado-category-card__children\");\n        for (const child of childCategories) {\n          const link = document.createElement(\"a\");\n          link.className = \"cado-category-child\";\n          link.href = categoryUrl(child, categoriesById);\n          link.innerHTML = `<span></span><strong>${countLabel(child.topic_count)}</strong>`;\n          link.querySelector(\"span\").textContent = child.name;\n          childrenElement.appendChild(link);\n        }\n\n        grid.appendChild(card);\n      }\n\n      document.querySelectorAll(`#${COMPONENT_ID}`).forEach((element) => element.remove());\n      anchor.parentNode.insertBefore(wrapper, anchor);\n    }\n\n    api.onPageChange(() => {\n      window.setTimeout(renderDirectory, 50);\n    });\n\n    window.setTimeout(renderDirectory, 50);\n  })();\n\n    });\n  }\n};\n","import \"virtual:init-settings\";\n\nconst themeCompatModules = {};\nimport * as Mod1 from \"./discourse/initializers/theme-field-1065-common-html-script-1\";\nthemeCompatModules[\"discourse/initializers/theme-field-1065-common-html-script-1\"] = Mod1;\n\nexport default themeCompatModules;\n"],"names":["registerSettings","getObjectForTheme","themeField1065CommonHtmlScript1","name","after","initialize","deprecated","id","url","withPluginApi","api","COMPONENT_ID","renderGeneration","countLabel","count","value","categoryUrl","category","categoriesById","parent","parent_category_id","get","slug","visibleCategory","read_restricted","startsWith","async","renderDirectory","attempt","generation","document","querySelectorAll","forEach","element","remove","getCurrentUser","path","window","location","pathname","replace","isAnonymousHomepage","anchor","querySelector","setTimeout","site","response","fetch","credentials","ok","json","categories","filter","Map","map","childrenByParent","has","set","push","topCategories","sort","a","b","topic_count","length","wrapper","createElement","className","innerHTML","grid","childCategories","card","style","setProperty","color","textContent","childrenElement","child","link","href","appendChild","parentNode","insertBefore","onPageChange","themeCompatModules","Mod1"],"mappings":";AAEAA,EAAiB,GAAI,CAAA,GCAGC,EAAkB;ACC1C,IAAAC,EAAe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