{"version":3,"file":"virtual_main.js","sources":["theme-56/virtual:init-settings","theme-56/virtual:theme","theme-56/discourse/components/featured-tile.gjs","theme-56/discourse/components/featured-tiles.gjs","theme-56/discourse/connectors/discovery-list-container-top/featured-tiles.gjs","theme-56/discourse/connectors/user-preferences-interface/featured-tiles.gjs","theme-56/discourse/initializers/init-featured-tiles.js","theme-56/virtual:main"],"sourcesContent":["import { registerSettings } from \"discourse/lib/theme-settings-store\";\n\nregisterSettings(56, {\n  \"featured_category\": 0,\n  \"featured_tags\": \"featured\",\n  \"topic_source\": \"latest\",\n  \"top_period\": \"yearly\",\n  \"randomize_topics\": true,\n  \"display_when_unfiltered\": true,\n  \"display_on_categories\": false,\n  \"display_categories\": \"\",\n  \"maximum_topic_count\": 5,\n  \"scope_to_category\": false,\n  \"display_mobile\": true\n});\n","import { getObjectForTheme } from \"discourse/lib/theme-settings-store\";\n\nexport const settings = getObjectForTheme(56);\n\nexport function themePrefix(key) {\n  return `theme_translations.56.${key}`;\n}\n","import Component from \"@ember/component\";\nimport { classNames } from \"@ember-decorators/component\";\nimport UserLink from \"discourse/components/user-link\";\nimport avatar from \"discourse/helpers/avatar\";\nimport discourseComputed from \"discourse/lib/decorators\";\n\n@classNames(\"featured-tile\")\nexport default class FeaturedTile extends Component {\n  responsiveRatios = [1, 1.5, 2];\n  displayHeight = 200;\n  displayWidth = 200;\n\n  @discourseComputed(\"topic.thumbnails\")\n  srcset() {\n    return this.responsiveRatios\n      .map((ratio) => {\n        const match = this.findBest(\n          ratio * this.displayHeight,\n          ratio * this.displayWidth\n        );\n        return `${match.url} ${ratio}x`;\n      })\n      .join(\",\");\n  }\n\n  @discourseComputed(\"topic.thumbnails\")\n  original(thumbnails) {\n    return thumbnails[0];\n  }\n\n  @discourseComputed(\"original\")\n  width(original) {\n    return original.width;\n  }\n\n  @discourseComputed(\"original\")\n  height(original) {\n    return original.height;\n  }\n\n  @discourseComputed(\"topic.thumbnails\")\n  fallbackSrc() {\n    return this.findBest(this.displayWidth, this.displayHeight).url;\n  }\n\n  findBest(maxWidth, maxHeight) {\n    if (!this.topic.thumbnails) {\n      return;\n    }\n\n    const largeEnough = this.topic.thumbnails.filter((t) => {\n      if (!t.url) {\n        return false;\n      }\n      return t.max_width >= maxHeight;\n    });\n\n    if (largeEnough.lastObject) {\n      return largeEnough.lastObject;\n    }\n\n    return this.original;\n  }\n\n  @discourseComputed(\"topic\")\n  url(topic) {\n    return topic.linked_post_number\n      ? topic.urlForPostNumber(topic.linked_post_number)\n      : topic.get(\"lastUnreadUrl\");\n  }\n\n  <template>\n    <a href={{this.url}}>\n      {{#if this.topic.thumbnails}}\n        <img\n          src={{this.fallbackSrc}}\n          srcset={{this.srcset}}\n          width={{this.width}}\n          height={{this.height}}\n          loading=\"lazy\"\n          class=\"topic-tile-thumbnail\"\n        />\n      {{/if}}\n\n      <div class=\"topic-info\">\n        <span class=\"topic-title\">{{this.topic.title}}</span>\n        <span class=\"author\">\n          <UserLink @user={{this.topic.creator}}>\n            {{avatar this.topic.creator imageSize=\"large\"}}\n          </UserLink>\n        </span>\n      </div>\n    </a>\n  </template>\n}\n","import Component from \"@ember/component\";\nimport { next } from \"@ember/runloop\";\nimport { service } from \"@ember/service\";\nimport { classNameBindings } from \"@ember-decorators/component\";\nimport { observes } from \"@ember-decorators/object\";\nimport PluginOutlet from \"discourse/components/plugin-outlet\";\nimport discourseComputed from \"discourse/lib/decorators\";\nimport FeaturedTile from \"./featured-tile\";\n\nconst displayCategories = settings.display_categories\n  .split(\"|\")\n  .map((id) => parseInt(id, 10))\n  .filter((id) => id);\n\nconst featuredTags = settings.featured_tags.split(\"|\").filter(Boolean);\n\nfunction shuffle(array) {\n  array = [...array];\n\n  // https://stackoverflow.com/a/12646864\n  for (let i = array.length - 1; i > 0; i--) {\n    const j = Math.floor(Math.random() * (i + 1));\n    [array[i], array[j]] = [array[j], array[i]];\n  }\n\n  return array;\n}\n\n@classNameBindings(\"isLoading\")\nexport default class FeaturedTiles extends Component {\n  @service router;\n\n  isLoading = true;\n\n  init() {\n    super.init();\n    this.set(\"isLoading\", true);\n    this.loadTopics();\n  }\n\n  @observes(\"category\")\n  categoryChanged() {\n    if (settings.scope_to_category) {\n      this.loadTopics();\n    }\n  }\n\n  loadTopics() {\n    const loadParams = { period: settings.top_period };\n\n    if (featuredTags.length) {\n      loadParams.tags = featuredTags;\n    }\n\n    if (settings.featured_category > 0) {\n      loadParams.category = settings.featured_category;\n    }\n\n    if (settings.scope_to_category && this.category) {\n      loadParams.category = this.category.id;\n    }\n\n    this.store\n      .findFiltered(\"topicList\", {\n        filter: settings.topic_source,\n        params: loadParams,\n      })\n      .then((list) => {\n        this.set(\"list\", list);\n        next(this, () => this.set(\"isLoading\", false)); // Use `next` for CSS animation\n      });\n  }\n\n  @discourseComputed(\"list.topics\")\n  filteredTopics(topics) {\n    if (!topics) {\n      return;\n    }\n    if (settings.randomize_topics) {\n      topics = shuffle(topics);\n    }\n    return topics.slice(0, settings.maximum_topic_count);\n  }\n\n  @discourseComputed(\n    \"site.mobileView\",\n    \"category.id\",\n    \"router.currentRouteName\"\n  )\n  shouldDisplay(isMobile, viewingCategoryId, currentRouteName) {\n    if (\n      ![\n        \"discovery.latest\",\n        \"discovery.categories\",\n        \"discovery.category\",\n      ].includes(currentRouteName)\n    ) {\n      return false;\n    }\n\n    if (isMobile && !settings.display_mobile) {\n      return false;\n    }\n    if (settings.display_when_unfiltered && !viewingCategoryId) {\n      return true;\n    }\n\n    if (settings.display_on_categories && viewingCategoryId) {\n      if (displayCategories.length === 0) {\n        return true;\n      }\n      return displayCategories.includes(viewingCategoryId);\n    }\n    return false;\n  }\n\n  <template>\n    {{#if this.shouldDisplay}}\n      <div class=\"featured-tiles-container\">\n        {{#each this.filteredTopics as |topic|}}\n          <FeaturedTile @topic={{topic}} />\n        {{/each}}\n      </div>\n\n      <PluginOutlet\n        @name=\"below-featured-tiles\"\n        @tagName=\"\"\n        @connectorTagName=\"div\"\n      />\n    {{/if}}\n  </template>\n}\n","import Component from \"@ember/component\";\nimport { classNames, tagName } from \"@ember-decorators/component\";\nimport FeaturedTiles from \"../../components/featured-tiles\";\n\n@tagName(\"span\")\n@classNames(\"discovery-list-container-top-outlet\", \"featured-tiles\")\nexport default class FeaturedTilesConnector extends Component {\n  static shouldRender() {\n    let val = window.localStorage.getItem(\"show_featured_topics_banner\");\n    if (val === \"false\") {\n      val = false;\n    }\n    if (val === null) {\n      val = true;\n    }\n    return val;\n  }\n\n  <template><FeaturedTiles @category={{this.category}} /></template>\n}\n","import Component from \"@ember/component\";\nimport { classNames } from \"@ember-decorators/component\";\nimport PreferenceCheckbox from \"discourse/components/preference-checkbox\";\nimport User from \"discourse/models/user\";\nimport { i18n } from \"discourse-i18n\";\n\n@classNames(\"user-preferences-interface-outlet\", \"featured-tiles\")\nexport default class FeaturedTiles extends Component {\n  static shouldRender(component) {\n    return component.model.id === User.current().id;\n  }\n\n  <template>\n    <div class=\"control-group other\">\n      <label class=\"control-label\">{{i18n\n          (themePrefix \"preference_header\")\n        }}</label>\n\n      <PreferenceCheckbox\n        @labelKey={{themePrefix \"preference_description\"}}\n        @checked={{this.model.show_featured_topics_banner}}\n      />\n    </div>\n  </template>\n}\n","import { action, observer } from \"@ember/object\";\nimport { withPluginApi } from \"discourse/lib/plugin-api\";\nimport User from \"discourse/models/user\";\n\nexport default {\n  name: \"discourse-featured-tiles\",\n\n  initialize() {\n    withPluginApi(\"0.8.9\", (api) => {\n      api.modifyClass(\"controller:preferences/interface\", {\n        pluginId: this.name,\n\n        updateShowFeaturedTopicsBanner: observer(\"model.id\", function () {\n          // debugger;\n          if (this.model.id !== User.current().id) {\n            return;\n          }\n          this.set(\n            \"model.show_featured_topics_banner\",\n            this.storedFeaturedTopicsValue()\n          );\n        }),\n\n        storedFeaturedTopicsValue() {\n          let val = window.localStorage.getItem(\"show_featured_topics_banner\");\n          if (val === \"false\") {\n            val = false;\n          }\n          if (val === null) {\n            val = true;\n          }\n          return !!val;\n        },\n      });\n\n      api.modifyClass(\n        \"controller:preferences/interface\",\n        (Superclass) =>\n          class extends Superclass {\n            @action\n            save() {\n              super.save();\n              if (this.model.id !== User.current().id) {\n                return;\n              }\n              if (\n                this.storedFeaturedTopicsValue() !==\n                this.model.show_featured_topics_banner\n              ) {\n                if (this.model.show_featured_topics_banner) {\n                  window.localStorage.removeItem(\"show_featured_topics_banner\");\n                } else {\n                  window.localStorage.setItem(\n                    \"show_featured_topics_banner\",\n                    false\n                  );\n                }\n              }\n            }\n          }\n      );\n    });\n  },\n};\n","import \"virtual:init-settings\";\n\nconst themeCompatModules = {};\nimport * as Mod1 from \"./discourse/components/featured-tile\";\nthemeCompatModules[\"discourse/components/featured-tile\"] = Mod1;\n\nimport * as Mod2 from \"./discourse/components/featured-tiles\";\nthemeCompatModules[\"discourse/components/featured-tiles\"] = Mod2;\n\nimport * as Mod3 from \"./discourse/connectors/discovery-list-container-top/featured-tiles\";\nthemeCompatModules[\"discourse/connectors/discovery-list-container-top/featured-tiles\"] = Mod3;\n\nimport * as Mod4 from \"./discourse/connectors/user-preferences-interface/featured-tiles\";\nthemeCompatModules[\"discourse/connectors/user-preferences-interface/featured-tiles\"] = Mod4;\n\nimport * as Mod5 from \"./discourse/initializers/init-featured-tiles\";\nthemeCompatModules[\"discourse/initializers/init-featured-tiles\"] = Mod5;\n\nexport default themeCompatModules;\n"],"names":["registerSettings","featured_category","featured_tags","topic_source","top_period","randomize_topics","display_when_unfiltered","display_on_categories","display_categories","maximum_topic_count","scope_to_category","display_mobile","settings","getObjectForTheme","themePrefix","key","FeaturedTile","dt7948","c","Component","responsiveRatios","displayHeight","displayWidth","srcset","this","map","ratio","findBest","url","join","static","n","prototype","discourseComputed","original","thumbnails","width","height","fallbackSrc","maxWidth","maxHeight","topic","largeEnough","filter","t","max_width","lastObject","linked_post_number","urlForPostNumber","get","setComponentTemplate","createTemplateFactory","id","block","moduleName","scope","UserLink","avatar","isStrictMode","classNames","displayCategories","split","parseInt","featuredTags","Boolean","FeaturedTiles","g","service","router","i","isLoading","init","super","set","loadTopics","categoryChanged","observes","loadParams","period","length","tags","category","store","findFiltered","params","then","list","next","filteredTopics","topics","array","j","Math","floor","random","shuffle","slice","shouldDisplay","isMobile","viewingCategoryId","currentRouteName","includes","PluginOutlet","classNameBindings","FeaturedTilesConnector","shouldRender","val","window","localStorage","getItem","tagName","component","model","User","current","i18n","PreferenceCheckbox","initFeaturedTiles","name","initialize","withPluginApi","api","modifyClass","pluginId","updateShowFeaturedTopicsBanner","observer","storedFeaturedTopicsValue","Superclass","save","show_featured_topics_banner","removeItem","setItem","action","themeCompatModules","Mod1","Mod2","Mod3","Mod4","Mod5"],"mappings":";AAEAA,EAAiB,GAAI,CACnBC,kBAAqB,EACrBC,cAAiB,WACjBC,aAAgB,SAChBC,WAAc,SACdC,kBAAoB,EACpBC,yBAA2B,EAC3BC,uBAAyB,EACzBC,mBAAsB,GACtBC,oBAAuB,EACvBC,mBAAqB,EACrBC,gBAAkB;ACXb,MAAMC,EAAWC,EAAkB;AAEnC,SAASC,EAAYC,GAC1B,MAAO,yBAAyBA,GAClC,CCFyD,MAGpCC,EAAAC,OAAAC,EAAA,cAAqBC,EACxCC,iBAAmB,CAAC,EAAG,IAAK;AAC5BC,cAAgB;AAChBC,aAAe;AAGfC,MAAAA,GACE,OAAOC,KAAKJ,iBACTK,IAAKC,GAKG,GAJOF,KAAKG,SACjBD,EAAQF,KAAKH,cACbK,EAAQF,KAAKF,cAECM,OAAOF,MAExBG,KAAK,IACV,CAAAC,SAAA,KAAAb,OAAAc,EAAAP,KAAAQ,UAAA,SAAA,CAXCC,EAAkB,sBAWnB;AAGAC,QAAAA,CAASC,GACP,OAAOA,EAAW,EACpB,CAAAL,SAAA,KAAAb,OAAAc,EAAAP,KAAAQ,UAAA,WAAA,CAHCC,EAAkB,sBAGnB;AAGAG,KAAAA,CAAMF,GACJ,OAAOA,EAASE,KAClB,CAAAN,SAAA,KAAAb,OAAAc,EAAAP,KAAAQ,UAAA,QAAA,CAHCC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