(function(e,o){typeof exports=="object"&&typeof module<"u"?module.exports=o(require("vue")):typeof define=="function"&&define.amd?define(["vue"],o):(e=typeof globalThis<"u"?globalThis:e||self,e.VueTyping=o(e.Vue))})(this,function(e){"use strict";const o={class:"sentence","data-id":"dmn-typing-sentence"};return e.defineComponent({__name:"dmnTyping",props:{sentences:{},minTypeSpeed:{default:50},maxTypeSpeed:{default:150},eraseSpeed:{default:100},eraseDelay:{default:1500},writeDelay:{default:0},caret:{default:"_"},loop:{type:Boolean,default:!1},tag:{default:"div"}},emits:["sentence:typed"],setup(h,{emit:v}){const t=h,S=v,d=e.ref(0),i=e.ref(""),p=e.ref(0),a=e.ref(!1),s=e.ref(0),l=e.ref(0);let r,u;const _=e.computed(()=>({caret:!0,typing:a.value}));function f(){e.nextTick(()=>{r=setTimeout(c,t.writeDelay)})}function c(){var n;l.value<((n=t.sentences[s.value])==null?void 0:n.length)?(a.value=!0,C()):D()}function C(){i.value+=t.sentences[s.value].charAt(l.value),l.value+=1;const n=w(t.minTypeSpeed,t.maxTypeSpeed);r=setTimeout(c,n)}function D(){if(S("sentence:typed",t.sentences[s.value]),p.value+=1,!t.loop&&p.value===t.sentences.length){a.value=!1;return}t.loop?(a.value=!1,u=setTimeout(m,t.eraseDelay)):y()}function m(){l.value>0?(a.value=!0,x()):(a.value=!1,y())}function x(){i.value=t.sentences[s.value].substring(0,l.value-1),l.value-=1,u=setTimeout(m,t.eraseSpeed)}function y(){s.value=(s.value+1)%t.sentences.length,(t.loop||s.value>0)&&(a.value=!0,l.value=0,r=setTimeout(c,t.writeDelay))}function w(n,T){return Math.floor(Math.random()*(T-n+1))+n}function g(){clearTimeout(r),clearTimeout(u)}return f(),e.onUnmounted(()=>{g()}),e.watch(t,()=>{g(),f(),d.value++},{deep:!0}),(n,T)=>(e.openBlock(),e.createBlock(e.resolveDynamicComponent(n.tag),{key:d.value,class:"dmn-typing","data-id":"dmn-typing"},{default:e.withCtx(()=>[e.renderSlot(n.$slots,"before",{dataId:"dmn-typing-before"}),e.createElementVNode("span",o,e.toDisplayString(i.value),1),e.createElementVNode("span",{class:e.normalizeClass(_.value),"data-id":"dmn-typing-caret"},e.toDisplayString(t.caret),3),e.renderSlot(n.$slots,"after",{dataId:"dmn-typing-after"})]),_:3}))}})});