(function(e,l){typeof exports=="object"&&typeof module<"u"?module.exports=l(require("vue")):typeof define=="function"&&define.amd?define(["vue"],l):(e=typeof globalThis<"u"?globalThis:e||self,e["vue-tweet"]=l(e.Vue))})(this,function(e){"use strict";return e.defineComponent({__name:"vue-tweet",props:{tweetId:{type:String,default:""},tweetUrl:{type:String,default:""},conversation:{type:String,default:"all",validator:t=>["all","none"].includes(t)},cards:{type:String,default:"visible",validator:t=>["visible","hidden"].includes(t)},width:{type:[String,Number],default:"auto",validator:t=>typeof t=="string"?t==="auto":typeof t=="number"?t>=250&&t<=550:!1},align:{type:[String,void 0],default:void 0,validator:t=>["left","right","center",void 0].includes(t)},theme:{type:String,default:"light",validator:t=>["light","dark"].includes(t)},lang:{type:String,default:"en",validator:t=>["ar","bn","cs","da","de","el","en","es","fa","fi","fil","fr","he","hi","hu","id","it","ja","ko","msa","nl","no","pl","pt","ro","ru","sv","th","tr","uk","ur","vi","zh-cn","zh-tw"].includes(t)},dnt:{type:Boolean,default:!1}},emits:{"tweet-load-success":t=>!!t,"tweet-load-error":t=>t},setup(t,{emit:p}){const f=t,w=p,d=e.ref(!0),a=e.ref(!1),s=e.ref();e.onMounted(()=>{u()}),e.watch(e.toRef(f),u,{deep:!0});function u(){if(!(window.twttr&&window.twttr.ready)){h("https://platform.twitter.com/widgets.js",u);return}window.twttr.ready().then(({widgets:r})=>{if(d.value=!0,a.value=!1,s.value)s.value.innerHTML="";else{console.error("tweetContainerRef is null");return}const{tweetId:n,tweetOptions:o}=m();r.createTweet(n,s.value,o).then(async i=>{await e.nextTick(),i?w("tweet-load-success",i):(a.value=!0,w("tweet-load-error",new Error("Failed to load tweet.")))}).finally(()=>{d.value=!1})}).catch(r=>{console.error("Error loading Twitter widget:",r),a.value=!0,d.value=!1})}function m(){var _;let{tweetId:r,tweetUrl:n,...o}=f,i=null;if(r&&n)i=new Error("Cannot provide both tweet-id and tweet-url.");else if(r)/^\d+$/.test(r)||(i=new Error("Invalid tweet-id, please provide a valid numerical tweet-id."));else if(n){const g=/^(https?:\/\/)?(www\.)?(twitter|x)\.com\/.*\/status(?:es)?\/(?[^/?]\d+)$/i,c=n.trim().match(g);c?r=(_=c.groups)==null?void 0:_.tweetId:i=new Error("Invalid tweet-url.")}else i=new Error("Must provide either tweet-id or tweet-url.");if(i)throw a.value=!0,d.value=!1,w("tweet-load-error",i),i;return{tweetId:r,tweetOptions:o}}function h(r,n){if(window.___$twitterScriptLoaded___===void 0&&(window.___$twitterScriptLoaded___=!1),window.___$twitterScriptLoaded___){n();return}if(window.___$twitterScriptLoading___===void 0&&(window.___$twitterScriptLoading___=!1),window.___$twitterScriptLoading___){const i=setInterval(()=>{window.___$twitterScriptLoaded___&&(clearInterval(i),n())},100);return}window.___$twitterScriptLoading___=!0;const o=document.createElement("script");o.setAttribute("src",r),o.async=!0,o.addEventListener("load",()=>{window.___$twitterScriptLoaded___=!0,window.___$twitterScriptLoading___=!1,n()},!1),document.body.appendChild(o)}return(r,n)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[a.value?e.renderSlot(r.$slots,"error",{key:0}):d.value?e.renderSlot(r.$slots,"loading",{key:1}):e.createCommentVNode("",!0),e.createElementVNode("div",e.mergeProps({ref_key:"tweetContainerRef",ref:s},r.$attrs),null,16)],64))}})});