!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["utils/comments/content-replace/handlers"]=t():e["utils/comments/content-replace/handlers"]=t()}(globalThis,(()=>(()=>{"use strict";var e={};const t=coreApis.pluginApis.data,n=coreApis.settings,r=e=>{try{const t=new URL(e);return Boolean(t)}catch(e){return!1}};class o{}const{options:s}=(0,n.getComponentSettings)("commentContentReplace"),c=[new class extends o{isKeywordMatch(e,t,n){return e instanceof Text&&(e.textContent.includes(t)&&r(n))}replaceContent(e,t,n){const r=e.textContent.indexOf(t);if(-1===r||!(e instanceof Text))return[];const o=new Text(e.textContent.substring(0,r)),s=((e,t)=>{const n=document.createElement("img");return n.src=e,n.alt=t,n.loading="lazy",n.style.width="50px",n.style.height="50px",n})(n,t),c=new Text(e.textContent.substring(r+t.length));return e.replaceWith(o,s,c),[c]}},new class extends o{isKeywordMatch(e,t,n){return e instanceof HTMLImageElement&&(e.alt===t&&r(n))}replaceContent(e,t,n){return e instanceof HTMLImageElement?(e.src=n,[]):[]}},new class extends o{isKeywordMatch(e,t){return e instanceof Text&&e.textContent.includes(t)}replaceContent(e,t,n){const r=e.textContent.indexOf(t);if(-1===r)return[];const o=e.textContent.substring(0,r),s=e.textContent.substring(r+t.length);return e.textContent=`${o}${n}${s}`,[]}},new class extends o{isKeywordMatch(e,t){return e instanceof HTMLImageElement&&e.alt===t}replaceContent(e,t,n){return e instanceof HTMLImageElement?(""===n?e.remove():e.replaceWith(new Text(n)),[]):[]}},new class extends o{isKeywordMatch(){return!0}replaceContent(e){return Array.from(e.childNodes)}}];(0,t.registerAndGetData)("commentContentReplace.handlers",[e=>{let{content:n}=e;const{replaceMap:r}=s,[o]=(0,t.registerAndGetData)("commentContentReplace.defaultHandler.replaceMap",r),a=e=>{e.forEach((e=>{Object.entries(o).forEach((t=>{let[n,r]=t;if(n===r||""===n)return;const o=c.find((t=>t.isKeywordMatch(e,n,r)));if(!o)return;const s=o.replaceContent(e,n,r);a(s)}))}))};a(n)}]);return e=e.component})()));