!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.CKEditor5=t():(e.CKEditor5=e.CKEditor5||{},e.CKEditor5.mediaEmbedCode=t())}(self,(()=>(()=>{var e={"ckeditor5/src/core.js":(e,t,d)=>{e.exports=d("dll-reference CKEditor5.dll")("./src/core.js")},"ckeditor5/src/widget.js":(e,t,d)=>{e.exports=d("dll-reference CKEditor5.dll")("./src/widget.js")},"dll-reference CKEditor5.dll":e=>{"use strict";e.exports=CKEditor5.dll}},t={};function d(i){var r=t[i];if(void 0!==r)return r.exports;var o=t[i]={exports:{}};return e[i](o,o.exports,d),o.exports}d.d=(e,t)=>{for(var i in t)d.o(t,i)&&!d.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},d.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var i={};return(()=>{"use strict";d.d(i,{default:()=>l});var e=d("ckeditor5/src/core.js");class t extends e.Plugin{static get pluginName(){return"DamMediaEmbedCodeEditing"}init(){const e=this.editor,t=e=>{const t=()=>{const d=document.querySelector('[data-cke-tooltip-text="View mode"]'),i=document.querySelector('[data-cke-tooltip-text="Embed code"]');d||i?e(d,i):setTimeout(t,100)};t()},d=(e,t,d)=>{e&&(e.style.display=d?"none":""),t&&(t.style.display=d?"":"none")},i=()=>{setTimeout((()=>{t(((t,i)=>{const r=(e=>e.some((e=>"drupalMedia"===e.name&&e.getAttribute("drupalElementStyleMediaEmbedCode"))))(Array.from(e.model.document.getRoot().getChildren()));d(t,i,r)}))}))};e.model.document.on("change",(()=>{const i=e.model.document.selection.getSelectedElement();i&&"drupalMedia"===i.name&&t(((e,t)=>{const r=i.getAttribute("drupalElementStyleMediaEmbedCode");d(e,t,!!r)}))})),e.model.on("deleteContent",i),e.model.on("insertContent",i),i()}}d("ckeditor5/src/widget.js");function r(e){for(const t of e){if(t.hasAttribute("data-drupal-media-preview"))return t;if(t.childCount){const e=r(t.getChildren());if(e)return e}}return null}class o extends e.Plugin{static get requires(){return["DrupalMediaEditing","DamMediaEmbedCodeEditing"]}static get pluginName(){return"MediaEmbedCodeEditing"}init(){const{editor:e}=this;e.model.schema.extend("drupalMedia",{allowAttributes:["embedCodeId","data-embed-code-id"]});const t=e.plugins.get("DrupalMediaEditing");t.attrs.embedCodeId="data-embed-code-id";this.editor.conversion.for("editingDowncast").add((e=>{e.on("attribute:drupalElementStyleMediaEmbedCode:drupalMedia",((e,d,i)=>{const o=i.writer,n=d.item,a=i.mapper.toViewElement(d.item);let l=r(a.getChildren());if(l){if("ready"!==l.getAttribute("data-drupal-media-preview"))return;o.setAttribute("data-drupal-media-preview","loading",l)}else l=o.createRawElement("div",{"data-drupal-media-preview":"loading"}),o.insert(o.createPositionAt(a,0),l);t._fetchPreview(n).then((({label:e,preview:t})=>{l&&this.editor.editing.view.change((d=>{const i=d.createRawElement("div",{"data-drupal-media-preview":"ready","aria-label":e},(e=>{e.innerHTML=t}));d.insert(d.createPositionBefore(l),i),d.remove(l)}))}))}))}))}}class n extends e.Plugin{static get requires(){return["DrupalMediaEditing"]}static get pluginName(){return"MediaEmbedCodeUI"}init(){const{editor:e}=this,t=e.editing.view.document;this.listenTo(t,"click",((t,d)=>{this._isSelectedLinkedMedia(e.model.document.selection)&&(d.preventDefault(),t.stop())}),{priority:"high"})}_isSelectedLinkedMedia(e){const t=e.getSelectedElement();return!!t&&t.is("element","drupalMedia")&&t.hasAttribute("drupalElementStyleMediaEmbedCode")}}class a extends e.Plugin{static get requires(){return[o,t,n]}static get pluginName(){return"MediaEmbedCode"}}const l={MediaEmbedCode:a}})(),i=i.default})()));