{"version":3,"file":"discourse-lazy-videos.js","names":["define","_exports","_component","_component2","_templateFactory","Object","defineProperty","value","default","LazyIframe","iframeSrc","this","args","providerName","url1","videoId","startTime","time1","match1","toString","match","hours1","minutes1","seconds1","slice","parseInt","convertToSeconds","includes","static","setComponentTemplate","createTemplateFactory","id","block","moduleName","isStrictMode","_tracking","_helper","_modifier","_object","_template2","_concatClass","_lazyIframe","LazyVideo","dt7948","g","prototype","tracked","isLoaded","i","thumbnailStyle","color1","videoAttributes","dominantColor","htmlSafe","loadEmbed","onLoadedVideo","n","action","onKeyPress","event1","key","preventDefault","scope","concat","on","_pluginApi","_lazyVideoAttributes","initLazyEmbed","api","decorateCookedElement","cooked","helper","classList","contains","querySelectorAll","forEach","container","siteSettings","lookup","postId","closest","dataset","preventCloak","lazyVideo","renderGlimmer","param","replaceWith","onlyStream","name","initialize","withPluginApi","url","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(time1) {\n    const match1 = time1.toString().match(/(?:(\\d+)h)?(?:(\\d+)m)?(?:(\\d+)s)?/);\n    const [hours1, minutes1, seconds1] = match1.slice(1);\n    if (hours1 || minutes1 || seconds1) {\n      const h1 = parseInt(hours1, 10) || 0;\n      const m1 = parseInt(minutes1, 10) || 0;\n      const s1 = parseInt(seconds1, 10) || 0;\n      return h1 * 3600 + m1 * 60 + s1;\n    }\n    return time1;\n  }\n  class LazyIframe extends _component.default {\n    get iframeSrc() {\n      switch (this.args.providerName) {\n        case \"youtube\":\n          let url1 = `https://www.youtube.com/embed/${this.args.videoId}?autoplay=1&rel=0`;\n          if (this.args.startTime) {\n            url1 += `&start=${convertToSeconds(this.args.startTime)}`;\n          }\n          return url1;\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 #_ = (() => (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\": \"QVZUreY8\",\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\\\"],false,[\\\"if\\\"]]\",\n      \"moduleName\": \"/code/current/app/assets/javascripts/discourse/discourse/plugins/discourse-lazy-videos/discourse/components/lazy-iframe.js\",\n      \"isStrictMode\": true\n    }), this))();\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/plugins/discourse-lazy-videos/discourse/components/lazy-iframe\", \"@ember/component\", \"@ember/template-factory\"], function (_exports, _component, _tracking, _helper, _modifier, _object, _template2, _concatClass, _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 #_ = (() => dt7948.g(this.prototype, \"isLoaded\", [_tracking.tracked], function () {\n      return false;\n    }))();\n    #isLoaded = (() => (dt7948.i(this, \"isLoaded\"), void 0))();\n    get thumbnailStyle() {\n      const color1 = this.args.videoAttributes.dominantColor;\n      if (color1?.match(/^[0-9A-Fa-f]+$/)) {\n        return (0, _template2.htmlSafe)(`background-color: #${color1};`);\n      }\n    }\n    loadEmbed() {\n      if (!this.isLoaded) {\n        this.isLoaded = true;\n        this.args.onLoadedVideo?.();\n      }\n    }\n    static #_2 = (() => dt7948.n(this.prototype, \"loadEmbed\", [_object.action]))();\n    onKeyPress(event1) {\n      if (event1.key === \"Enter\") {\n        event1.preventDefault();\n        this.loadEmbed();\n      }\n    }\n    static #_3 = (() => dt7948.n(this.prototype, \"onKeyPress\", [_object.action]))();\n    static #_4 = (() => (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.loadEmbed}}\n              tabindex=\"0\"\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\": \"E9HrROuM\",\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,\\\"tabindex\\\",\\\"0\\\"],[16,5,[30,0,[\\\"thumbnailStyle\\\"]]],[16,0,[28,[32,0],[\\\"video-thumbnail\\\",[30,1,[\\\"providerName\\\"]]],null]],[4,[32,3],[\\\"click\\\",[30,0,[\\\"loadEmbed\\\"]]],null],[4,[32,3],[\\\"keypress\\\",[30,0,[\\\"loadEmbed\\\"]]],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\\\"],false,[\\\"if\\\"]]\",\n      \"moduleName\": \"/code/current/app/assets/javascripts/discourse/discourse/plugins/discourse-lazy-videos/discourse/components/lazy-video.js\",\n      \"scope\": () => [_concatClass.default, _helper.concat, _lazyIframe.default, _modifier.on],\n      \"isStrictMode\": true\n    }), this))();\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/lib/lazy-video-attributes\", \"@ember/template-factory\"], function (_exports, _pluginApi, _lazyVideoAttributes, _templateFactory) {\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 = helper.renderGlimmer(\"p.lazy-video-wrapper\", (0, _templateFactory.createTemplateFactory)(\n          /*\n            <LazyVideo @videoAttributes={{@data.param}} @onLoadedVideo={{@data.onLoadedVideo}}/>\n          */\n          {\n            \"id\": \"DiQBlm+J\",\n            \"block\": \"[[[8,[39,0],null,[[\\\"@videoAttributes\\\",\\\"@onLoadedVideo\\\"],[[30,1,[\\\"param\\\"]],[30,1,[\\\"onLoadedVideo\\\"]]]],null]],[\\\"@data\\\"],false,[\\\"lazy-video\\\"]]\",\n            \"moduleName\": \"/code/current/app/assets/javascripts/discourse/discourse/plugins/discourse-lazy-videos/initializers/lazy-videos.js\",\n            \"isStrictMode\": false\n          }), {\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)(\"1.6.0\", 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,mKAAAC,EAAAC,EAAAC,EAAAC,GACA;AAEAC,OAAAC,eAAAL,EAAA,cACAM,OAAA,IAEAN,EAAAO,aAAA;AAYA,MAAAC,UAAAP,EAAAM,QACA,aAAAE,GACA,OAAAC,KAAAC,KAAAC,cACA,cACA,IAAAC,EAAA,iCAAAH,KAAAC,KAAAG;AAIA,OAHAJ,KAAAC,KAAAI,YACAF,GAAA,UAjBA,SAAAG,GACA,MAAAC,EAAAD,EAAAE,WAAAC,MAAA,sCACAC,EAAAC,EAAAC,GAAAL,EAAAM,MAAA;AACA,GAAAH,GAAAC,GAAAC,EAIA,aAHAE,SAAAJ,EAAA,QAGA,IAFAI,SAAAH,EAAA,SACAG,SAAAF,EAAA;AAGA,OAAAN,CACA,CAOAS,CAAAf,KAAAC,KAAAI,cAEAF;AACA,YACA,wCAAAH,KAAAC,KAAAG,UAAAJ,KAAAC,KAAAG,QAAAY,SAAA;AACA,aACA,yCAAAhB,KAAAC,K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