{"version":3,"file":"main.Be8Ji9.js","sources":["theme-9/virtual:theme","theme-9/vendor/minimasonry.js","theme-9/discourse/components/gif-result.gjs","theme-9/discourse/components/gif-result-list.gjs","theme-9/discourse/components/modal/gif.gjs","theme-9/discourse/initializers/gif-integration.js","theme-9/virtual:entrypoint:main"],"sourcesContent":["import { getObjectForTheme } from \"discourse/lib/theme-settings-store\";\n\nexport const settings = getObjectForTheme(9);\n\nexport function themePrefix(key) {\n  return `theme_translations.9.${key}`;\n}\n","/** @type MiniMasonry */\nvar MiniMasonry = function(conf) {\n    this._sizes             = [];\n    this._columns           = [];\n    this._container         = null;\n    this._count             = null;\n    this._width             = 0;\n    this._removeListener    = null;\n    this._currentGutterX    = null;\n    this._currentGutterY    = null;\n\n    this._resizeTimeout = null,\n\n    this.conf = {\n        baseWidth: 255,\n        gutterX: null,\n        gutterY: null,\n        gutter: 10,\n        container: null,\n        minify: true,\n        ultimateGutter: 5,\n        surroundingGutter: true,\n        direction: 'ltr',\n        wedge: false\n    };\n\n    this.init(conf);\n\n    return this;\n}\n\nMiniMasonry.prototype.init = function(conf) {\n    for (var i in this.conf) {\n        if (conf[i] != undefined) {\n            this.conf[i] = conf[i];\n        }\n    }\n\n    if (this.conf.gutterX == null || this.conf.gutterY == null) {\n        this.conf.gutterX = this.conf.gutterY = this.conf.gutter;\n    }\n    this._currentGutterX = this.conf.gutterX;\n    this._currentGutterY = this.conf.gutterY;\n\n    this._container = typeof this.conf.container == 'object' && this.conf.container.nodeName ?\n        this.conf.container :\n        document.querySelector(this.conf.container);\n\n    if (!this._container) {\n        throw new Error('Container not found or missing');\n    }\n\n    var onResize = this.resizeThrottler.bind(this)\n    window.addEventListener(\"resize\", onResize);\n    this._removeListener = function() {\n        window.removeEventListener(\"resize\", onResize);\n        if (this._resizeTimeout != null) {\n            window.clearTimeout(this._resizeTimeout);\n            this._resizeTimeout = null;\n        }\n    }\n\n    this.layout();\n};\n\nMiniMasonry.prototype.reset = function() {\n    this._sizes   = [];\n    this._columns = [];\n    this._count   = null;\n    this._width   = this._container.clientWidth;\n    var minWidth  = this.conf.baseWidth;\n    if (this._width < minWidth) {\n        this._width = minWidth;\n        this._container.style.minWidth = minWidth + 'px';\n    }\n\n    if (this.getCount() == 1) {\n        // Set ultimate gutter when only one column is displayed\n        this._currentGutterX = this.conf.ultimateGutter;\n        // As gutters are reduced, two column may fit, forcing to 1\n        this._count = 1;\n    } else if (this._width < (this.conf.baseWidth + (2 * this._currentGutterX))) {\n        // Remove gutter when screen is to low\n        this._currentGutterX = 0;\n    } else {\n        this._currentGutterX = this.conf.gutterX;\n    }\n};\n\nMiniMasonry.prototype.getCount = function() {\n    if (this.conf.surroundingGutter) {\n        return Math.floor((this._width - this._currentGutterX) / (this.conf.baseWidth + this._currentGutterX));\n    }\n\n    return Math.floor((this._width + this._currentGutterX) / (this.conf.baseWidth + this._currentGutterX));\n}\n\nMiniMasonry.prototype.computeWidth = function() {\n    var width;\n    if (this.conf.surroundingGutter) {\n        width = ((this._width - this._currentGutterX) / this._count) - this._currentGutterX;\n    } else {\n        width = ((this._width + this._currentGutterX) / this._count) - this._currentGutterX;\n    }\n    width = Number.parseFloat(width.toFixed(2));\n\n    return width;\n}\n\nMiniMasonry.prototype.layout =  function() {\n    if (!this._container) {\n        console.error('Container not found');\n        return;\n    }\n    this.reset();\n\n    //Computing columns count\n    if (this._count == null) {\n        this._count = this.getCount();\n    }\n    //Computing columns width\n    var colWidth = this.computeWidth();\n\n    for (var i = 0; i < this._count; i++) {\n        this._columns[i] = 0;\n    }\n\n    //Saving children real heights\n    var children = this._container.children;\n    for (var k = 0;k< children.length; k++) {\n        // Set colWidth before retrieving element height if content is proportional\n        children[k].style.width = colWidth + 'px';\n        this._sizes[k] = children[k].clientHeight;\n    }\n\n    var startX;\n    if (this.conf.direction == 'ltr') {\n        startX = this.conf.surroundingGutter ? this._currentGutterX : 0;\n    } else {\n        startX = this._width - (this.conf.surroundingGutter ? this._currentGutterX : 0);\n    }\n    if (this._count > this._sizes.length) {\n        //If more columns than children\n        var occupiedSpace = (this._sizes.length * (colWidth + this._currentGutterX)) - this._currentGutterX;\n        if (this.conf.wedge === false) {\n            if (this.conf.direction == 'ltr') {\n                startX = ((this._width - occupiedSpace) / 2);\n            } else {\n                startX = this._width - ((this._width - occupiedSpace) / 2);\n            }\n        } else {\n            if (this.conf.direction == 'ltr') {\n                //\n            } else {\n                startX = this._width - this._currentGutterX;\n            }\n        }\n    }\n\n    //Computing position of children\n    for (var index = 0;index < children.length; index++) {\n        var nextColumn = this.conf.minify ? this.getShortest() : this.getNextColumn(index);\n\n        var childrenGutter = 0;\n        if (this.conf.surroundingGutter || nextColumn != this._columns.length) {\n            childrenGutter = this._currentGutterX;\n        }\n        var x;\n        if (this.conf.direction == 'ltr') {\n            x = startX + ((colWidth + childrenGutter) * (nextColumn));\n        } else {\n            x = startX - ((colWidth + childrenGutter) * (nextColumn)) - colWidth;\n        }\n        var y = this._columns[nextColumn];\n\n\n        children[index].style.transform = 'translate3d(' + Math.round(x) + 'px,' + Math.round(y) + 'px,0)';\n\n        this._columns[nextColumn] += this._sizes[index] + (this._count > 1 ? this.conf.gutterY : this.conf.ultimateGutter);//margin-bottom\n    }\n\n    this._container.style.height = (this._columns[this.getLongest()] - this._currentGutterY) + 'px';\n};\n\nMiniMasonry.prototype.getNextColumn = function(index) {\n    return index % this._columns.length;\n};\n\nMiniMasonry.prototype.getShortest = function() {\n    var shortest = 0;\n    for (var i = 0; i < this._count; i++) {\n        if (this._columns[i] < this._columns[shortest]) {\n            shortest = i;\n        }\n    }\n\n    return shortest;\n};\n\nMiniMasonry.prototype.getLongest = function() {\n    var longest = 0;\n    for (var i = 0; i < this._count; i++) {\n        if (this._columns[i] > this._columns[longest]) {\n            longest = i;\n        }\n    }\n\n    return longest;\n};\n\nMiniMasonry.prototype.resizeThrottler = function() {\n    // ignore resize events as long as an actualResizeHandler execution is in the queue\n    if ( !this._resizeTimeout ) {\n\n        this._resizeTimeout = setTimeout(function() {\n            this._resizeTimeout = null;\n            //IOS Safari throw random resize event on scroll, call layout only if size has changed\n            if (this._container.clientWidth != this._width) {\n                this.layout();\n            }\n           // The actualResizeHandler will execute at a rate of 30fps\n        }.bind(this), 33);\n    }\n}\n\nMiniMasonry.prototype.destroy = function() {\n    if (typeof this._removeListener == \"function\") {\n        this._removeListener();\n    }\n\n    var children = this._container.children;\n    for (var k = 0;k< children.length; k++) {\n        children[k].style.removeProperty('width');\n        children[k].style.removeProperty('transform');\n    }\n    this._container.style.removeProperty('height');\n    this._container.style.removeProperty('min-width');\n}\n\nexport default MiniMasonry;\n","import Component from \"@glimmer/component\";\nimport { fn } from \"@ember/helper\";\nimport { on } from \"@ember/modifier\";\nimport { action } from \"@ember/object\";\nimport { htmlSafe } from \"@ember/template\";\nimport concatClass from \"discourse/helpers/concat-class\";\n\nexport default class GifResult extends Component {\n  get style() {\n    const { width, height } = this.args.gif;\n\n    if (width && height) {\n      return htmlSafe(`--aspect-ratio: ${width / height};`);\n    }\n  }\n\n  @action\n  keyDown(event) {\n    if (event.key === \"Enter\") {\n      this.args.pick(this.args.gif);\n    }\n  }\n\n  <template>\n    <div\n      {{on \"click\" (fn @pick @gif)}}\n      {{on \"keydown\" this.keyDown}}\n      role=\"button\"\n      tabindex=\"0\"\n      class={{concatClass\n        \"gif-imgwrap\"\n        (if @gif.isCategory \"gif-category-item\")\n      }}\n    >\n      <img\n        class=\"gif-img\"\n        alt={{@gif.title}}\n        title={{@gif.title}}\n        src={{@gif.preview}}\n        style={{this.style}}\n        width={{@gif.width}}\n        height={{@gif.height}}\n      />\n      {{#if @gif.isCategory}}\n        <span class=\"gif-category-label\">{{@gif.title}}</span>\n      {{/if}}\n    </div>\n  </template>\n}\n","import Component from \"@glimmer/component\";\nimport { action } from \"@ember/object\";\nimport didInsert from \"@ember/render-modifiers/modifiers/did-insert\";\nimport didUpdate from \"@ember/render-modifiers/modifiers/did-update\";\nimport { schedule } from \"@ember/runloop\";\nimport { service } from \"@ember/service\";\nimport ConditionalLoadingSpinner from \"discourse/components/conditional-loading-spinner\";\nimport MiniMasonry from \"../../vendor/minimasonry\";\nimport GifResult from \"./gif-result\";\n\nexport default class GifResultList extends Component {\n  @service site;\n\n  observer;\n  masonry;\n\n  willDestroy() {\n    super.willDestroy(...arguments);\n    this.observer.disconnect();\n  }\n\n  @action\n  setup() {\n    this.observer = new IntersectionObserver(() => {\n      const scroller = document.querySelector(\".gif-content\");\n      // ensure we don't load more if we haven't scrolled at all\n      if (scroller?.scrollTop > 0 && this.args.content?.length > 0) {\n        this.args.loadMore?.();\n      }\n    });\n\n    let target = document.querySelector(\"div.gif-box div.loading-container\");\n    this.observer.observe(target);\n\n    this.masonry = new MiniMasonry({\n      container: \".gif-result-list\",\n      baseWidth: this.site.mobileView ? 145 : 200,\n      surroundingGutter: false,\n    });\n\n    schedule(\"afterRender\", () => this.masonry.layout());\n  }\n\n  @action\n  update() {\n    schedule(\"afterRender\", () => this.masonry.layout());\n  }\n\n  <template>\n    <div\n      {{didInsert this.setup}}\n      {{didUpdate this.update @content.length}}\n      class=\"gif-result-list\"\n    >\n      {{#each @content key=\"preview\" as |result|}}\n        <GifResult @gif={{result}} @pick={{@pick}} />\n      {{/each}}\n\n      <ConditionalLoadingSpinner @condition={{@loading}} />\n    </div>\n  </template>\n}\n","import Component from \"@glimmer/component\";\nimport { tracked } from \"@glimmer/tracking\";\nimport { Input } from \"@ember/component\";\nimport { on } from \"@ember/modifier\";\nimport { action } from \"@ember/object\";\nimport { service } from \"@ember/service\";\nimport { modifier } from \"ember-modifier\";\nimport DModal from \"discourse/components/d-modal\";\nimport loadingSpinner from \"discourse/helpers/loading-spinner\";\nimport { addUniqueValuesToArray } from \"discourse/lib/array-tools\";\nimport discourseDebounce from \"discourse/lib/debounce\";\nimport { trackedArray } from \"discourse/lib/tracked-tools\";\nimport { i18n } from \"discourse-i18n\";\nimport GifResultList from \"../gif-result-list\";\n\nexport default class Gif extends Component {\n  @service appEvents;\n  @service dialog;\n\n  @tracked categories = [];\n  @tracked loading = false;\n  @tracked loadingCategories = false;\n  @tracked offset = 0;\n  @tracked query = \"\";\n  @trackedArray currentGifs = [];\n\n  onModalInsert = modifier(() => {\n    this.fetchCategories();\n  });\n\n  get providerLogo() {\n    return settings.theme_uploads[`${settings.api_provider}-logo`];\n  }\n\n  get showingCategories() {\n    return (\n      settings.api_provider === \"klipy\" &&\n      this.query.length < 3 &&\n      this.categories.length > 0\n    );\n  }\n\n  @action\n  pick(content) {\n    let markup = [\n      \"\\n\",\n      `![${content.title}|${content.width}x${content.height}](${content.original})`,\n      \"\\n\",\n    ].join(\"\");\n\n    if (this.args.model?.customPickHandler) {\n      this.args.model.customPickHandler(markup);\n    } else {\n      this.appEvents.trigger(\"composer:insert-text\", markup);\n    }\n\n    this.args.closeModal();\n  }\n\n  @action\n  async loadMore() {\n    if (!this.loading) {\n      await this.search(false);\n    }\n  }\n\n  @action\n  refresh(event) {\n    this.query = event.target.value;\n    discourseDebounce(this, this.search, 700);\n  }\n\n  @action\n  selectCategory(category) {\n    this.query = category.searchterm;\n    this.search(true, true);\n  }\n\n  async fetchCategories() {\n    if (settings.api_provider !== \"klipy\" || settings.klipy_api_key === \"\") {\n      return;\n    }\n\n    this.loadingCategories = true;\n\n    try {\n      const params = {\n        key: settings.klipy_api_key,\n        country: settings.klipy_country,\n        locale: settings.klipy_locale,\n        type: \"featured\",\n        contentfilter: settings.klipy_content_filter,\n      };\n\n      const response = await fetch(\n        \"https://api.klipy.com/v2/categories?\" + new URLSearchParams(params)\n      );\n\n      if (this.isDestroying || this.isDestroyed) {\n        return;\n      }\n\n      if (!response.ok) {\n        return;\n      }\n\n      const data = await response.json();\n\n      if (this.isDestroying || this.isDestroyed) {\n        return;\n      }\n\n      const tags = data.tags || [];\n      this.categories = await this.loadCategoryDimensions(tags);\n    } catch {\n      // Silently fail - user can still search manually\n    } finally {\n      this.loadingCategories = false;\n    }\n  }\n\n  async loadCategoryDimensions(tags) {\n    const loadImage = (tag) => {\n      return new Promise((resolve) => {\n        const img = new Image();\n        img.onload = () => {\n          resolve({\n            title: tag.name,\n            preview: tag.image,\n            original: tag.image,\n            width: img.naturalWidth,\n            height: img.naturalHeight,\n            isCategory: true,\n            searchterm: tag.searchterm,\n          });\n        };\n        img.onerror = () => {\n          resolve({\n            title: tag.name,\n            preview: tag.image,\n            original: tag.image,\n            width: 200,\n            height: 150,\n            isCategory: true,\n            searchterm: tag.searchterm,\n          });\n        };\n        img.src = tag.image;\n      });\n    };\n\n    return Promise.all(tags.map(loadImage));\n  }\n\n  async search(clearResults = true, skipLengthCheck = false) {\n    if (clearResults) {\n      this.currentGifs = [];\n      this.offset = 0;\n    }\n\n    const meetsLengthRequirement = skipLengthCheck || this.query.length > 2;\n\n    // Check for minimum search query and if search result limit was set & reached\n    if (\n      (meetsLengthRequirement && !settings.limit_infinite_search_results) ||\n      (settings.limit_infinite_search_results &&\n        this.currentGifs.length < settings.max_results_limit)\n    ) {\n      this.loading = true;\n\n      try {\n        if (\n          (settings.api_provider === \"tenor\" &&\n            settings.tenor_api_key === \"\") ||\n          (settings.api_provider === \"giphy\" &&\n            settings.giphy_api_key === \"\") ||\n          (settings.api_provider === \"klipy\" && settings.klipy_api_key === \"\")\n        ) {\n          throw new Error(`${settings.api_provider.toUpperCase()} API key is not set. Site Admins, \\\n            please visit the \"Discourse Gifs\" theme-component topic on Discourse Meta \\\n            for setup instructions.`);\n        }\n\n        const response = await fetch(this.getEndpoint(this.query, this.offset));\n\n        if (this.isDestroying || this.isDestroyed) {\n          return;\n        }\n\n        if (!response.ok) {\n          // Use the same errorMsg variable to handle variable replacement at the end for API Provider Display Name $api_provider.\n          let errorMsg;\n\n          // Only check for certain errors if setting is configured to do so.\n          // This is to allow server admins time & the choice to update the custom messages. Existing Plugin users will have this setting disabled by default.\n          if (response.status === 429) {\n            errorMsg = i18n(themePrefix(\"gif.error_rate_limit\"));\n          } else if (response.status === 414) {\n            errorMsg = i18n(themePrefix(\"gif.error_search_too_long\"));\n          } else if (response.status === 403 || response.status === 401) {\n            errorMsg = i18n(themePrefix(\"gif.bad_api_key\"));\n          }\n\n          // Parse Error Messages from Tenor/Klipy if one isn't set yet\n          if (\n            !errorMsg &&\n            (settings.api_provider === \"tenor\" ||\n              settings.api_provider === \"klipy\") &&\n            response.headers.get(\"content-type\")?.includes(\"application/json\")\n          ) {\n            const errorResponse = await response.json();\n\n            // Check for API Key Errors first\n            if (\n              errorResponse.error.details.find(\n                (e) => e.reason === \"API_KEY_INVALID\"\n              ) !== undefined\n            ) {\n              errorMsg = i18n(themePrefix(\"gif.bad_api_key\"));\n            } else {\n              // Map Error Message according to default Google API standards\n              throw new Error(\n                `Tenor Error Code ${errorResponse.error.code}: ${\n                  errorResponse.error.message\n                } [${errorResponse.error.details\n                  .map((e) => e.reason)\n                  .join(\", \")}]`\n              );\n            }\n          }\n\n          // If error message is set, check if the API Provider variable was used.\n          // Replace if needed - throw at the end of it.\n          if (errorMsg) {\n            throw new Error(\n              errorMsg.replaceAll(\n                \"$api_provider\",\n                settings.api_provider.toUpperCase()\n              )\n            );\n          } else {\n            // Fallback to returning the entire response along with a status code.\n            throw new Error(\n              `${settings.api_provider.toUpperCase()} Status ${\n                response.status\n              }: ${await response.text()}`\n            );\n          }\n        }\n\n        const data = await response.json();\n        if (this.isDestroying || this.isDestroyed) {\n          return;\n        }\n\n        let images;\n\n        if (settings.api_provider === \"giphy\") {\n          images = data.data.map((gif) => {\n            const sizeVariant = gif.images[settings.giphy_size_variant];\n            const isWebp = settings.giphy_file_format === \"webp\";\n\n            return {\n              title: gif.title,\n              preview:\n                settings.giphy_file_format === \"webp\"\n                  ? gif.images.fixed_width.webp\n                  : gif.images.fixed_width.url,\n              original:\n                isWebp && sizeVariant.webp ? sizeVariant.webp : sizeVariant.url,\n              width: parseInt(sizeVariant.width, 10),\n              height: parseInt(sizeVariant.height, 10),\n            };\n          });\n        } else if (settings.api_provider === \"klipy\") {\n          // Klipy: uses same URL for preview and original\n          const fileDetail = settings.klipy_file_detail;\n          images = data.results.map((gif) => {\n            const media_format = gif.media_formats[fileDetail];\n\n            return {\n              title: gif.title,\n              preview: media_format.url,\n              original: media_format.url,\n              width: media_format.dims[0],\n              height: media_format.dims[1],\n            };\n          });\n        } else {\n          // Tenor\n          const fileDetail = settings.tenor_file_detail;\n          images = data.results.map((gif) => {\n            const hasTinyGif = \"tinygif\" in gif.media_formats;\n\n            // Use user-defined file format for attached GIFS and \"preview\" as a backup\n            const media_format =\n              fileDetail in gif.media_formats\n                ? gif.media_formats[fileDetail]\n                : gif.media_formats.preview;\n\n            return {\n              title: gif.title,\n              preview: hasTinyGif\n                ? gif.media_formats.tinygif.url\n                : gif.media_formats.preview.url,\n              original: media_format.url,\n              width: media_format.dims[0],\n              height: media_format.dims[1],\n            };\n          });\n        }\n\n        // Handle offset differences between Giphy and Tenor\n        this.offset =\n          settings.api_provider === \"giphy\"\n            ? data.pagination.offset + data.pagination.count\n            : data.next === \"\"\n              ? 0\n              : data.next;\n\n        addUniqueValuesToArray(this.currentGifs, images);\n      } catch (error) {\n        this.dialog.alert({ message: error });\n      } finally {\n        this.loading = false;\n      }\n    }\n  }\n\n  getEndpoint(query, offset) {\n    if (\n      settings.api_provider === \"tenor\" ||\n      settings.api_provider === \"klipy\"\n    ) {\n      const isKlipy = settings.api_provider === \"klipy\";\n      const apiKey = isKlipy ? settings.klipy_api_key : settings.tenor_api_key;\n      const fileDetail = isKlipy\n        ? settings.klipy_file_detail\n        : settings.tenor_file_detail;\n\n      let params = {\n        key: apiKey,\n        q: query,\n        country: isKlipy ? settings.klipy_country : settings.tenor_country,\n        locale: isKlipy ? settings.klipy_locale : settings.tenor_locale,\n        contentfilter: isKlipy\n          ? settings.klipy_content_filter\n          : settings.tenor_content_filter,\n        media_filter: fileDetail,\n        limit: 24,\n        pos: offset,\n      };\n\n      // Tenor-specific: client_key parameter\n      if (!isKlipy && settings.tenor_client_key !== \"\") {\n        params.client_key = settings.tenor_client_key;\n      }\n\n      // Tenor: include tinygif for preview and \"preview\" for backup\n      // Klipy: no preview formats needed, uses the main format directly\n      if (!isKlipy) {\n        params.media_filter +=\n          fileDetail !== \"tinygif\" ? \",tinygif,preview\" : \",preview\";\n      }\n\n      const baseUrl = isKlipy\n        ? \"https://api.klipy.com/v2/search\"\n        : \"https://tenor.googleapis.com/v2/search\";\n\n      return baseUrl + \"?\" + new URLSearchParams(params);\n    } else {\n      // GIPHY\n      return (\n        \"https://api.giphy.com/v1/gifs/search?\" +\n        new URLSearchParams({\n          limit: 24,\n          q: query,\n          offset,\n          api_key: settings.giphy_api_key,\n          lang: settings.giphy_locale,\n          rating: settings.giphy_content_rating,\n        })\n      );\n    }\n  }\n\n  <template>\n    <DModal\n      {{this.onModalInsert}}\n      @title={{i18n (themePrefix \"gif.modal_title\")}}\n      @closeModal={{@closeModal}}\n      id=\"gif-modal\"\n      class=\"gif-modal\"\n    >\n      <:body>\n        <div class=\"gif-input\">\n          <Input\n            {{on \"input\" this.refresh}}\n            @type=\"text\"\n            @value={{this.query}}\n            name=\"query\"\n            autofocus\n          />\n\n          {{#if this.loading}}\n            {{loadingSpinner size=\"small\"}}\n          {{/if}}\n        </div>\n\n        {{#if this.currentGifs.length}}\n          <div class=\"gif-content\">\n            <div class=\"gif-box\">\n              <GifResultList\n                @content={{this.currentGifs}}\n                @pick={{this.pick}}\n                @loading={{this.loading}}\n                @loadMore={{this.loadMore}}\n              />\n            </div>\n          </div>\n        {{else if this.showingCategories}}\n          <div class=\"gif-content\">\n            <h3 class=\"gif-categories-header\">{{i18n\n                (themePrefix \"gif.browse_categories\")\n              }}</h3>\n            <div class=\"gif-box\">\n              <GifResultList\n                @content={{this.categories}}\n                @pick={{this.selectCategory}}\n                @loading={{false}}\n              />\n            </div>\n          </div>\n        {{else if this.loadingCategories}}\n          <div class=\"gif-loading-categories\">\n            {{loadingSpinner size=\"medium\"}}\n          </div>\n        {{else}}\n          <div class=\"gif-no-results\">{{i18n\n              (themePrefix \"gif.no_results\")\n            }}</div>\n        {{/if}}\n      </:body>\n\n      <:footer>\n        <img src={{this.providerLogo}} />\n      </:footer>\n    </DModal>\n  </template>\n}\n","import { addGlobalNotice } from \"discourse/components/global-notice\";\nimport getURL from \"discourse/lib/get-url\";\nimport { withPluginApi } from \"discourse/lib/plugin-api\";\nimport GifModal from \"../components/modal/gif\";\n\nexport default {\n  name: \"discourse-gifs\",\n\n  initialize(container) {\n    withPluginApi((api) => {\n      const siteSettings = api.container.lookup(\"service:site-settings\");\n\n      if (siteSettings.enable_gifs) {\n        if (api.getCurrentUser()?.admin) {\n          const themeId = themePrefix(\"id\").match(\n            /theme_translations\\.(\\d+)\\./\n          )[1];\n          const themeURL = getURL(`/admin/customize/themes/${themeId}`);\n\n          addGlobalNotice(\n            `<b>Admin notice:</b> you're using the <em>discourse-gifs</em> theme component. GIF support is now built into Discourse core (the <em>enable gifs</em> site setting is enabled). You should <a href=\"${themeURL}\">remove this theme component</a> and see <a href=\"https://meta.discourse.org/t/gifs-are-moving-to-discourse-core/404829\">the announcement</a> on how to replace it.`,\n            \"discourse-gifs-theme\",\n            {\n              dismissable: true,\n              level: \"warn\",\n              dismissDuration: moment.duration(\"1\", \"hour\"),\n            }\n          );\n        }\n\n        // return early if core implementation is enabled\n        return;\n      }\n\n      api.onToolbarCreate((toolbar) => {\n        if (toolbar.context.composerEvents) {\n          toolbar.addButton({\n            title: themePrefix(\"gif.composer_title\"),\n            id: \"gif_button\",\n            group: \"extras\",\n            icon: \"discourse-gifs-gif\",\n            action: () => {\n              const modal = api.container.lookup(\"service:modal\");\n              modal.show(GifModal);\n            },\n          });\n        }\n      });\n\n      const chat = api.container.lookup(\"service:chat\");\n      const currentUser = api.container.lookup(\"service:current-user\");\n\n      if (chat) {\n        const modal = api.container.lookup(\"service:modal\");\n        api.registerChatComposerButton({\n          translatedLabel: themePrefix(\"gif.composer_title\"),\n          id: \"gif_button\",\n          icon: \"discourse-gifs-gif\",\n          position: \"dropdown\",\n          async action(context) {\n            await modal.show(GifModal, {\n              model: {\n                customPickHandler: (message) => {\n                  api.sendChatMessage(this.draft.channel.id, {\n                    message,\n                    threadId:\n                      context === \"thread\" ? this.draft.thread.id : null,\n                    inReplyToId:\n                      context === \"channel\" ? this.draft.inReplyTo?.id : null,\n                  });\n                },\n              },\n            });\n\n            this.draft.channel.resetDraft(currentUser);\n          },\n        });\n      }\n    });\n\n    // for old tenor gifs compat\n    const caps = container.lookup(\"service:capabilities\");\n    if (caps.isSafari || caps.isIOS) {\n      document.documentElement.classList.add(\"discourse-gifs-with-img\");\n    }\n  },\n};\n","import * as Mod1 from \"./discourse/components/gif-result-list\";\nimport * as Mod2 from \"./discourse/components/gif-result\";\nimport * as Mod3 from \"./discourse/components/modal/gif\";\nimport * as Mod4 from \"./discourse/initializers/gif-integration\";\nimport * as Mod5 from \"./vendor/minimasonry\";\nconst compatModules = {\n  \"discourse/components/gif-result-list\": Mod1,\n  \"discourse/components/gif-result\": Mod2,\n  \"discourse/components/modal/gif\": Mod3,\n  \"discourse/initializers/gif-integration\": Mod4,\n  \"vendor/minimasonry\": Mod5,\n};\nexport { compatModules };\nexport default compatModules;\n"],"names":["settings","getObjectForTheme","themePrefix","key","MiniMasonry","conf","this","_sizes","_columns","_container","_count","_width","_removeListener","_currentGutterX","_currentGutterY","_resizeTimeout","baseWidth","gutterX","gutterY","gutter","container","minify","ultimateGutter","surroundingGutter","direction","wedge","init","prototype","i","undefined","nodeName","document","querySelector","Error","onResize","resizeThrottler","bind","window","addEventListener","removeEventListener","clearTimeout","layout","reset","clientWidth","minWidth","style","getCount","Math","floor","computeWidth","width","Number","parseFloat","toFixed","colWidth","startX","children","k","length","clientHeight","occupiedSpace","index","x","nextColumn","getShortest","getNextColumn","childrenGutter","y","transform","round","height","getLongest","console","error","shortest","longest","setTimeout","destroy","removeProperty","GifResult","Component","args","gif","htmlSafe","keyDown","event","pick","dt7948","n","action","setComponentTemplate","createTemplateFactory","id","block","moduleName","scope","concatClass","on","fn","isStrictMode","GifResultList","g","service","site","observer","masonry","willDestroy","super","arguments","disconnect","setup","IntersectionObserver","scroller","scrollTop","content","loadMore","target","observe","mobileView","schedule","update","didInsert","didUpdate","ConditionalLoadingSpinner","Gif","appEvents","dialog","tracked","categories","loading","loadingCategories","offset","query","trackedArray","currentGifs","onModalInsert","modifier","fetchCategories","providerLogo","theme_uploads","api_provider","showingCategories","markup","title","original","join","model","customPickHandler","trigger","closeModal","search","refresh","value","discourseDebounce","selectCategory","category","searchterm","klipy_api_key","params","country","klipy_country","locale","klipy_locale","type","contentfilter","klipy_content_filter","response","fetch","URLSearchParams","isDestroying","isDestroyed","ok","data","json","tags","loadCategoryDimensions","Promise","all","map","tag","resolve","img","Image","onload","name","preview","image","naturalWidth","naturalHeight","isCategory","onerror","src","clearResults","skipLengthCheck","limit_infinite_search_results","max_results_limit","tenor_api_key","giphy_api_key","toUpperCase","getEndpoint","errorMsg","status","i18n","headers","get","includes","errorResponse","details","find","e","reason","code","message","replaceAll","text","images","sizeVariant","giphy_size_variant","isWebp","giphy_file_format","fixed_width","webp","url","parseInt","fileDetail","klipy_file_detail","results","media_format","media_formats","dims","tenor_file_detail","hasTinyGif","tinygif","pagination","count","next","addUniqueValuesToArray","alert","isKlipy","apiKey","q","tenor_country","tenor_locale","tenor_content_filter","media_filter","limit","pos","tenor_client_key","client_key","api_key","lang","giphy_locale","rating","giphy_content_rating","DModal","Input","loadingSpinner","gifIntegration","initialize","withPluginApi","api","lookup","enable_gifs","getCurrentUser","admin","themeId","match","themeURL","getURL","addGlobalNotice","dismissable","level","dismissDuration","moment","duration","onToolbarCreate","toolbar","context","composerEvents","addButton","group","icon","show","GifModal","chat","currentUser","modal","registerChatComposerButton","translatedLabel","position","sendChatMessage","draft","channel","threadId","thread","inReplyToId","inReplyTo","resetDraft","caps","isSafari","isIOS","documentElement","classList","add","compatModules","Mod1","Mod2","Mod3","Mod5"],"mappings":"u4DAEaA,EAAWC,EAAkB;AAEnC,SAASC,EAAYC,GAC1B,MAAO,wBAAwBA,GACjC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