{"version":3,"file":"discourse-lazy-videos.js","names":["define","_exports","_component","_component2","_templateFactory","Object","defineProperty","value","default","LazyIframe","iframeSrc","this","args","providerName","url","videoId","startTime","time","match","toString","hours","minutes","seconds","slice","parseInt","convertToSeconds","includes","setComponentTemplate","createTemplateFactory","id","block","moduleName","isStrictMode","_tracking","_helper","_modifier","_object","_template","_concatClass","_discourseI18n","_lazyIframe","LazyVideo","dt7948","g","prototype","tracked","isLoaded","i","thumbnailStyle","color","videoAttributes","dominantColor","htmlSafe","loadEmbed","onLoadedVideo","n","action","onKeyPress","event","key","preventDefault","scope","concat","i18n","on","_pluginApi","_lazyVideo","_lazyVideoAttributes","_templateOnly","initLazyEmbed","api","decorateCookedElement","cooked","helper","classList","contains","querySelectorAll","forEach","container","siteSettings","lookup","postId","closest","dataset","preventCloak","lazyVideo","document","createElement","add","renderGlimmer","undefined","param","replaceWith","onlyStream","name","initialize","withPluginApi","querySelector","getAttribute","img","thumbnail","title","videoTitle","videoStartTime"],"sources":["discourse/plugins/discourse-lazy-videos/discourse/components/lazy-iframe.js","discourse/plugins/discourse-lazy-videos/discourse/components/lazy-video.js","discourse/plugins/discourse-lazy-videos/initializers/lazy-videos.js","discourse/plugins/discourse-lazy-videos/lib/lazy-video-attributes.js"],"sourcesContent":["define(\"discourse/plugins/discourse-lazy-videos/discourse/components/lazy-iframe\", [\"exports\", \"@glimmer/component\", \"@ember/component\", \"@ember/template-factory\"], function (_exports, _component, _component2, _templateFactory) {\n  \"use strict\";\n\n  Object.defineProperty(_exports, \"__esModule\", {\n    value: true\n  });\n  _exports.default = void 0;\n  function convertToSeconds(time) {\n    const match = time.toString().match(/(?:(\\d+)h)?(?:(\\d+)m)?(?:(\\d+)s)?/);\n    const [hours, minutes, seconds] = match.slice(1);\n    if (hours || minutes || seconds) {\n      const h = parseInt(hours, 10) || 0;\n      const m = parseInt(minutes, 10) || 0;\n      const s = parseInt(seconds, 10) || 0;\n      return h * 3600 + m * 60 + s;\n    }\n    return time;\n  }\n  class LazyIframe extends _component.default {\n    get iframeSrc() {\n      switch (this.args.providerName) {\n        case \"youtube\":\n          let url = `https://www.youtube.com/embed/${this.args.videoId}?autoplay=1&rel=0`;\n          if (this.args.startTime) {\n            url += `&start=${convertToSeconds(this.args.startTime)}`;\n          }\n          return url;\n        case \"vimeo\":\n          return `https://player.vimeo.com/video/${this.args.videoId}${this.args.videoId.includes(\"?\") ? \"&\" : \"?\"}autoplay=1`;\n        case \"tiktok\":\n          return `https://www.tiktok.com/embed/v2/${this.args.videoId}`;\n      }\n    }\n    static {\n      (0, _component2.setComponentTemplate)((0, _templateFactory.createTemplateFactory)(\n      /*\n        \n          {{#if @providerName}}\n            <iframe\n              src={{this.iframeSrc}}\n              title={{@title}}\n              allowFullScreen\n              scrolling=\"no\"\n              frameborder=\"0\"\n              seamless=\"seamless\"\n              allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\"\n            ></iframe>\n          {{/if}}\n        \n      */\n      {\n        \"id\": \"AkavoMLZ\",\n        \"block\": \"[[[1,\\\"\\\\n\\\"],[41,[30,1],[[[1,\\\"      \\\"],[10,\\\"iframe\\\"],[15,\\\"src\\\",[30,0,[\\\"iframeSrc\\\"]]],[15,\\\"title\\\",[30,2]],[14,\\\"allowFullScreen\\\",\\\"\\\"],[14,\\\"scrolling\\\",\\\"no\\\"],[14,\\\"frameborder\\\",\\\"0\\\"],[14,\\\"seamless\\\",\\\"seamless\\\"],[14,\\\"allow\\\",\\\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\\\"],[12],[13],[1,\\\"\\\\n\\\"]],[]],null],[1,\\\"  \\\"]],[\\\"@providerName\\\",\\\"@title\\\"],[\\\"if\\\"]]\",\n        \"moduleName\": \"/var/www/discourse/frontend/discourse/discourse/plugins/discourse-lazy-videos/discourse/components/lazy-iframe.js\",\n        \"isStrictMode\": true\n      }), this);\n    }\n  }\n  _exports.default = LazyIframe;\n});","define(\"discourse/plugins/discourse-lazy-videos/discourse/components/lazy-video\", [\"exports\", \"@glimmer/component\", \"@glimmer/tracking\", \"@ember/helper\", \"@ember/modifier\", \"@ember/object\", \"@ember/template\", \"discourse/helpers/concat-class\", \"discourse-i18n\", \"discourse/plugins/discourse-lazy-videos/discourse/components/lazy-iframe\", \"@ember/component\", \"@ember/template-factory\"], function (_exports, _component, _tracking, _helper, _modifier, _object, _template, _concatClass, _discourseI18n, _lazyIframe, _component2, _templateFactory) {\n  \"use strict\";\n\n  Object.defineProperty(_exports, \"__esModule\", {\n    value: true\n  });\n  _exports.default = void 0;\n  class LazyVideo extends _component.default {\n    static {\n      dt7948.g(this.prototype, \"isLoaded\", [_tracking.tracked], function () {\n        return false;\n      });\n    }\n    #isLoaded = (dt7948.i(this, \"isLoaded\"), void 0);\n    get thumbnailStyle() {\n      const color = this.args.videoAttributes.dominantColor;\n      if (color?.match(/^[0-9A-Fa-f]+$/)) {\n        return (0, _template.htmlSafe)(`background-color: #${color};`);\n      }\n    }\n    loadEmbed() {\n      if (!this.isLoaded) {\n        this.isLoaded = true;\n        this.args.onLoadedVideo?.();\n      }\n    }\n    static {\n      dt7948.n(this.prototype, \"loadEmbed\", [_object.action]);\n    }\n    onKeyPress(event) {\n      if (event.key === \"Enter\" || event.key === \" \") {\n        event.preventDefault();\n        this.loadEmbed();\n      }\n    }\n    static {\n      dt7948.n(this.prototype, \"onKeyPress\", [_object.action]);\n    }\n    static {\n      (0, _component2.setComponentTemplate)((0, _templateFactory.createTemplateFactory)(\n      /*\n        \n          <div\n            data-video-id={{@videoAttributes.id}}\n            data-video-title={{@videoAttributes.title}}\n            data-video-start-time={{@videoAttributes.startTime}}\n            data-provider-name={{@videoAttributes.providerName}}\n            class={{concatClass\n              \"lazy-video-container\"\n              (concat @videoAttributes.providerName \"-onebox\")\n              (if this.isLoaded \"video-loaded\")\n            }}\n          >\n            {{#if this.isLoaded}}\n              <LazyIframe\n                @providerName={{@videoAttributes.providerName}}\n                @title={{@videoAttributes.title}}\n                @videoId={{@videoAttributes.id}}\n                @startTime={{@videoAttributes.startTime}}\n              />\n            {{else}}\n              <div\n                {{on \"click\" this.loadEmbed}}\n                {{on \"keypress\" this.onKeyPress}}\n                role=\"button\"\n                tabindex=\"0\"\n                aria-label={{i18n\n                  \"lazy_videos.play_video\"\n                  title=@videoAttributes.title\n                }}\n                style={{this.thumbnailStyle}}\n                class={{concatClass \"video-thumbnail\" @videoAttributes.providerName}}\n              >\n                <img\n                  src={{@videoAttributes.thumbnail}}\n                  title={{@videoAttributes.title}}\n                  loading=\"lazy\"\n                  class={{concat @videoAttributes.providerName \"-thumbnail\"}}\n                />\n                <div\n                  class={{concatClass\n                    \"icon\"\n                    (concat @videoAttributes.providerName \"-icon\")\n                  }}\n                ></div>\n              </div>\n              <div class=\"title-container\">\n                <div class=\"title-wrapper\">\n                  <a\n                    href={{@videoAttributes.url}}\n                    title={{@videoAttributes.title}}\n                    target=\"_blank\"\n                    rel=\"noopener noreferrer\"\n                    class=\"title-link\"\n                  >\n                    {{@videoAttributes.title}}\n                  </a>\n                </div>\n              </div>\n            {{/if}}\n          </div>\n        \n      */\n      {\n        \"id\": \"IW7/krPx\",\n        \"block\": \"[[[1,\\\"\\\\n    \\\"],[10,0],[15,\\\"data-video-id\\\",[30,1,[\\\"id\\\"]]],[15,\\\"data-video-title\\\",[30,1,[\\\"title\\\"]]],[15,\\\"data-video-start-time\\\",[30,1,[\\\"startTime\\\"]]],[15,\\\"data-provider-name\\\",[30,1,[\\\"providerName\\\"]]],[15,0,[28,[32,0],[\\\"lazy-video-container\\\",[28,[32,1],[[30,1,[\\\"providerName\\\"]],\\\"-onebox\\\"],null],[52,[30,0,[\\\"isLoaded\\\"]],\\\"video-loaded\\\"]],null]],[12],[1,\\\"\\\\n\\\"],[41,[30,0,[\\\"isLoaded\\\"]],[[[1,\\\"        \\\"],[8,[32,2],null,[[\\\"@providerName\\\",\\\"@title\\\",\\\"@videoId\\\",\\\"@startTime\\\"],[[30,1,[\\\"providerName\\\"]],[30,1,[\\\"title\\\"]],[30,1,[\\\"id\\\"]],[30,1,[\\\"startTime\\\"]]]],null],[1,\\\"\\\\n\\\"]],[]],[[[1,\\\"        \\\"],[11,0],[24,\\\"role\\\",\\\"button\\\"],[24,\\\"tabindex\\\",\\\"0\\\"],[16,\\\"aria-label\\\",[28,[32,3],[\\\"lazy_videos.play_video\\\"],[[\\\"title\\\"],[[30,1,[\\\"title\\\"]]]]]],[16,5,[30,0,[\\\"thumbnailStyle\\\"]]],[16,0,[28,[32,0],[\\\"video-thumbnail\\\",[30,1,[\\\"providerName\\\"]]],null]],[4,[32,4],[\\\"click\\\",[30,0,[\\\"loadEmbed\\\"]]],null],[4,[32,4],[\\\"keypress\\\",[30,0,[\\\"onKeyPress\\\"]]],null],[12],[1,\\\"\\\\n          \\\"],[10,\\\"img\\\"],[15,\\\"src\\\",[30,1,[\\\"thumbnail\\\"]]],[15,\\\"title\\\",[30,1,[\\\"title\\\"]]],[14,\\\"loading\\\",\\\"lazy\\\"],[15,0,[28,[32,1],[[30,1,[\\\"providerName\\\"]],\\\"-thumbnail\\\"],null]],[12],[13],[1,\\\"\\\\n          \\\"],[10,0],[15,0,[28,[32,0],[\\\"icon\\\",[28,[32,1],[[30,1,[\\\"providerName\\\"]],\\\"-icon\\\"],null]],null]],[12],[13],[1,\\\"\\\\n        \\\"],[13],[1,\\\"\\\\n        \\\"],[10,0],[14,0,\\\"title-container\\\"],[12],[1,\\\"\\\\n          \\\"],[10,0],[14,0,\\\"title-wrapper\\\"],[12],[1,\\\"\\\\n            \\\"],[10,3],[15,6,[30,1,[\\\"url\\\"]]],[15,\\\"title\\\",[30,1,[\\\"title\\\"]]],[14,\\\"target\\\",\\\"_blank\\\"],[14,\\\"rel\\\",\\\"noopener noreferrer\\\"],[14,0,\\\"title-link\\\"],[12],[1,\\\"\\\\n              \\\"],[1,[30,1,[\\\"title\\\"]]],[1,\\\"\\\\n            \\\"],[13],[1,\\\"\\\\n          \\\"],[13],[1,\\\"\\\\n        \\\"],[13],[1,\\\"\\\\n\\\"]],[]]],[1,\\\"    \\\"],[13],[1,\\\"\\\\n  \\\"]],[\\\"@videoAttributes\\\"],[\\\"if\\\"]]\",\n        \"moduleName\": \"/var/www/discourse/frontend/discourse/discourse/plugins/discourse-lazy-videos/discourse/components/lazy-video.js\",\n        \"scope\": () => [_concatClass.default, _helper.concat, _lazyIframe.default, _discourseI18n.i18n, _modifier.on],\n        \"isStrictMode\": true\n      }), this);\n    }\n  }\n  _exports.default = LazyVideo;\n});","define(\"discourse/plugins/discourse-lazy-videos/initializers/lazy-videos\", [\"exports\", \"discourse/lib/plugin-api\", \"discourse/plugins/discourse-lazy-videos/discourse/components/lazy-video\", \"discourse/plugins/discourse-lazy-videos/lib/lazy-video-attributes\", \"@ember/component\", \"@ember/template-factory\", \"@ember/component/template-only\"], function (_exports, _pluginApi, _lazyVideo, _lazyVideoAttributes, _component, _templateFactory, _templateOnly) {\n  \"use strict\";\n\n  Object.defineProperty(_exports, \"__esModule\", {\n    value: true\n  });\n  _exports.default = void 0;\n  function initLazyEmbed(api) {\n    api.decorateCookedElement((cooked, helper) => {\n      if (cooked.classList.contains(\"d-editor-preview\")) {\n        return;\n      }\n      const lazyContainers = cooked.querySelectorAll(\".lazy-video-container\");\n      lazyContainers.forEach(container => {\n        const siteSettings = api.container.lookup(\"service:site-settings\");\n        const videoAttributes = (0, _lazyVideoAttributes.default)(container);\n        if (siteSettings[`lazy_${videoAttributes.providerName}_enabled`]) {\n          const onLoadedVideo = () => {\n            const postId = cooked.closest(\"article\")?.dataset?.postId;\n            if (postId) {\n              api.preventCloak(parseInt(postId, 10));\n            }\n          };\n          const lazyVideo = document.createElement(\"p\");\n          lazyVideo.classList.add(\"lazy-video-wrapper\");\n          helper.renderGlimmer(lazyVideo, (0, _component.setComponentTemplate)((0, _templateFactory.createTemplateFactory)(\n          /*\n            \n                        <LazyVideo\n                          @videoAttributes={{@data.param}}\n                          @onLoadedVideo={{@data.onLoadedVideo}}\n                        />\n                      \n          */\n          {\n            \"id\": \"bYFIM0WD\",\n            \"block\": \"[[[1,\\\"\\\\n              \\\"],[8,[32,0],null,[[\\\"@videoAttributes\\\",\\\"@onLoadedVideo\\\"],[[30,1,[\\\"param\\\"]],[30,1,[\\\"onLoadedVideo\\\"]]]],null],[1,\\\"\\\\n            \\\"]],[\\\"@data\\\"],[]]\",\n            \"moduleName\": \"/var/www/discourse/frontend/discourse/discourse/plugins/discourse-lazy-videos/initializers/lazy-videos.js\",\n            \"scope\": () => [_lazyVideo.default],\n            \"isStrictMode\": true\n          }), (0, _templateOnly.default)(undefined, undefined)), {\n            param: videoAttributes,\n            onLoadedVideo\n          });\n          container.replaceWith(lazyVideo);\n        }\n      });\n    }, {\n      onlyStream: true\n    });\n  }\n  var _default = _exports.default = {\n    name: \"discourse-lazy-videos\",\n    initialize() {\n      (0, _pluginApi.withPluginApi)(initLazyEmbed);\n    }\n  };\n});","define(\"discourse/plugins/discourse-lazy-videos/lib/lazy-video-attributes\", [\"exports\"], function (_exports) {\n  \"use strict\";\n\n  Object.defineProperty(_exports, \"__esModule\", {\n    value: true\n  });\n  _exports.default = getVideoAttributes;\n  function getVideoAttributes(cooked) {\n    if (!cooked.classList.contains(\"lazy-video-container\")) {\n      return {};\n    }\n    const url = cooked.querySelector(\"a\")?.getAttribute(\"href\");\n    const img = cooked.querySelector(\"img\");\n    const thumbnail = img?.getAttribute(\"src\");\n    const dominantColor = img?.dataset?.dominantColor;\n    const title = cooked.dataset.videoTitle;\n    const startTime = cooked.dataset.videoStartTime;\n    const providerName = cooked.dataset.providerName;\n    const id = cooked.dataset.videoId;\n    return {\n      url,\n      thumbnail,\n      title,\n      providerName,\n      id,\n      dominantColor,\n      startTime\n    };\n  }\n});"],"mappings":"AAAAA,OAAA,kKAAAC,EAAAC,EAAAC,EAAAC,GACA;AAEAC,OAAAC,eAAAL,EAAA,cACAM,OAAA,IAEAN,EAAAO,aAAA;AAYA,MAAAC,UAAAP,EAAAM,QACA,aAAAE,GACA,OAAAC,K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