{"version":3,"file":"virtual_main.js","sources":["theme-94/virtual:init-settings","theme-94/virtual:theme","theme-94/discourse/api-initializers/restore_video_preloading_metadata.js","theme-94/virtual:main"],"sourcesContent":["import { registerSettings } from \"discourse/lib/theme-settings-store\";\n\nregisterSettings(94, {});\n","import { getObjectForTheme } from \"discourse/lib/theme-settings-store\";\n\nexport const settings = getObjectForTheme(94);\n\nexport function themePrefix(key) {\n  return `theme_translations.94.${key}`;\n}\n","import { withPluginApi } from \"discourse/lib/plugin-api\";\nimport { iconHTML } from \"discourse-common/lib/icon-library\";\nimport discourseLater from \"discourse-common/lib/later\";\nimport I18n from \"I18n\";\n\n// Replace:\n// -\n// <div class=\"video-placeholder-container\" data-video-src=\"...\">\n//   <div class=\"video-placeholder-wrapper\">\n//     <div class=\"video-placeholder-overlay\">\n//       ...\n//     </div>\n//   </div>\n// </div>\n//\n// To:\n// -\n// <div class=\"video-container\" data-video-src=\"...\">\n//   <video width=\"100%\" height=\"100%\" preload=\"metadata\" controls>\n//     <source src=\"...\" ...>\n//     <a href=\"...\">...</a>\n//   </video>\n// </div>\n//\nfunction handleVideoContainer(element, owner) {\n  element\n    .querySelectorAll(\".video-placeholder-container\")\n    .forEach((videoContainer) => {\n      videoContainer.classList.replace(\n        \"video-placeholder-container\",\n        \"video-container\"\n      );\n\n      videoContainer.innerHTML = `\n        <video width=\"100%\" height=\"100%\" preload=\"metadata\" controls>\n          <source src=\"${videoContainer.dataset.videoSrc}\" ${videoContainer.dataset.origSrc}>\n          <a href=\"${videoContainer.dataset.videoSrc}\">${videoContainer.dataset.videoSrc}</a>\n        </video>`;\n\n      const caps = owner.lookup(\"service:capabilities\");\n      if (caps.isSafari || caps.isIOS) {\n        const source = videoContainer.querySelector(\"source\");\n        if (source) {\n          // In post-cooked.js, we create the video element in a detached DOM\n          // then adopt it into to the real DOM.\n          // This confuses safari, and preloading/autoplay do not happen.\n\n          // Calling `.load()` tricks Safari into loading the video element correctly\n          source.parentElement.load();\n        }\n      }\n\n      const video = videoContainer.getElementsByTagName(\"video\")[0];\n\n      video.addEventListener(\"loadeddata\", () => {\n        discourseLater(() => {\n          if (video.videoWidth === 0 || video.videoHeight === 0) {\n            const notice = document.createElement(\"div\");\n            notice.className = \"notice\";\n            notice.innerHTML =\n              iconHTML(\"exclamation-triangle\") +\n              \" \" +\n              I18n.t(\"cannot_render_video\");\n\n            videoContainer.appendChild(notice);\n          }\n        }, 500);\n      });\n    });\n}\n\nexport default {\n  initialize(owner) {\n    withPluginApi(\"0.8.7\", (api) => {\n      api.decorateCookedElement(\n        (element) => handleVideoContainer(element, owner),\n        { onlyStream: true }\n      );\n    });\n  },\n};\n","import \"virtual:init-settings\";\n\nconst themeCompatModules = {};\nimport * as Mod1 from \"./discourse/api-initializers/restore_video_preloading_metadata\";\nthemeCompatModules[\"discourse/api-initializers/restore_video_preloading_metadata\"] = Mod1;\n\nexport default themeCompatModules;\n"],"names":["registerSettings","getObjectForTheme","restore_video_preloading_metadata","initialize","owner","withPluginApi","api","decorateCookedElement","element","querySelectorAll","forEach","videoContainer","classList","replace","innerHTML","dataset","videoSrc","origSrc","caps","lookup","isSafari","isIOS","source","querySelector","parentElement","load","video","getElementsByTagName","addEventListener","discourseLater","videoWidth","videoHeight","notice","document","createElement","className","iconHTML","I18n","t","appendChild","handleVideoContainer","onlyStream","themeCompatModules","Mod1"],"mappings":";AAEAA,EAAiB,GAAI,CAAA,GCAGC,EAAkB;ACqE1C,IAAAC,EAAe,CACbC,UAAAA,CAAWC,GACTC,EAAc,QAAUC,IACtBA,EAAIC,sBACDC,GAnDT,SAA8BA,EAASJ,GACrCI,EACGC,iBAAiB,gCACjBC,QAASC,IACRA,EAAeC,UAAUC,QACvB,8BACA,mBAGFF,EAAeG,UAAY,oGAERH,EAAeI,QAAQC,aAAaL,EAAeI,QAAQE,gCAC/DN,EAAeI,QAAQC,aAAaL,EAAeI,QAAQC;AAG1E,MAAME,EAAOd,EAAMe,OAAO;AAC1B,GAAID,EAAKE,UAAYF,EAAKG,MAAO,CAC/B,MAAMC,EAASX,EAAeY,cAAc;AACxCD,GAMFA,EAAOE,cAAcC,MAEzB,CAEA,MAAMC,EAAQf,EAAegB,qBAAqB,SAAS;AAE3DD,EAAME,iBAAiB,aAAc,KACnCC,EAAe,KACb,GAAyB,IAArBH,EAAMI,YAA0C,IAAtBJ,EAAMK,YAAmB,CACrD,MAAMC,EAASC,SAASC,cAAc;AACtCF,EAAOG,UAAY,SACnBH,EAAOlB,UACLsB,EAAS,wBACT,IACAC,EAAKC,EAAE,uBAET3B,EAAe4B,YAAYP,EAC7B,GACC,QAGX,CAMqBQ,CAAqBhC,EAASJ,GAC3C,CAAEqC,YAAY,KAGpB;AC7EG,MAACC,EAAqB,CAAA;AAE3BA,EAAmB,gEAAkEC;"}