{"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","static","setComponentTemplate","createTemplateFactory","id","block","moduleName","isStrictMode","_tracking","_helper","_modifier","_object","_template","_concatClass","_lazyIframe","LazyVideo","dt7948","g","prototype","tracked","isLoaded","i","thumbnailStyle","color","videoAttributes","dominantColor","htmlSafe","loadEmbed","onLoadedVideo","n","action","onKeyPress","event","key","preventDefault","scope","concat","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 #_ = (() => (0, _component2.setComponentTemplate)((0, _templateFactory.createTemplateFactory)(\n /*\n \n {{#if @providerName}}\n \n {{/if}}\n \n */\n {\n \"id\": \"GBbnVjZj\",\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\": \"/var/www/discourse/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, _template, _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 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 #_2 = (() => dt7948.n(this.prototype, \"loadEmbed\", [_object.action]))();\n onKeyPress(event) {\n if (event.key === \"Enter\") {\n event.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 \n {{#if this.isLoaded}}\n \n {{else}}\n \n \n \n \n
\n
\n \n {{@videoAttributes.title}}\n \n
\n
\n {{/if}}\n \n \n */\n {\n \"id\": \"1eaF/Mtc\",\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\": \"/var/www/discourse/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/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 \n \n */\n {\n \"id\": \"vCh/9WDW\",\n \"block\": \"[[[1,\\\"\\\\n \\\"],[8,[32,0],null,[[\\\"@videoAttributes\\\",\\\"@onLoadedVideo\\\"],[[30,1,[\\\"param\\\"]],[30,1,[\\\"onLoadedVideo\\\"]]]],null],[1,\\\"\\\\n \\\"]],[\\\"@data\\\"],false,[]]\",\n \"moduleName\": \"/var/www/discourse/app/assets/javascripts/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,KAAAC,KAAAC,cACA,cACA,IAAAC,EAAA,iCAAAH,KAAAC,KAAAG;AAIA,OAHAJ,KAAAC,KAAAI,YACAF,GAAA,UAjBA,SAAAG,GACA,MAAAC,EAAAD,EAAAE,WAAAD,MAAA,sCACAE,EAAAC,EAAAC,GAAAJ,EAAAK,MAAA;AACA,GAAAH,GAAAC,GAAAC,EAIA,aAHAE,SAAAJ,EAAA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