vue-glitched-writer
Version:
Vue.js Single File Component. Wrapper for Glitched Writer: text-writing js module.
1 lines • 29.9 kB
JavaScript
var VueGlitchedWriter=function(t){"use strict";function e(t,e){var s=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),s.push.apply(s,i)}return s}function s(t){for(var s=1;s<arguments.length;s++){var i=null!=arguments[s]?arguments[s]:{};s%2?e(Object(i),!0).forEach((function(e){n(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):e(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function i(t){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function n(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}function r(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var s=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null==s)return;var i,n,r=[],o=!0,a=!1;try{for(s=s.call(t);!(o=(i=s.next()).done)&&(r.push(i.value),!e||r.length!==e);o=!0);}catch(t){a=!0,n=t}finally{try{o||null==s.return||s.return()}finally{if(a)throw n}}return r}(t,e)||function(t,e){if(!t)return;if("string"==typeof t)return o(t,e);var s=Object.prototype.toString.call(t).slice(8,-1);"Object"===s&&t.constructor&&(s=t.constructor.name);if("Map"===s||"Set"===s)return Array.from(t);if("Arguments"===s||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(s))return o(t,e)}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var s=0,i=new Array(e);s<e;s++)i[s]=t[s];return i}var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function l(t,e,s){return t(s={path:e,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&s.path)}},s.exports),s.exports}var h=l((function(t,e){function s(t,e,s){const i=Math.random()*(e-t)+t;if(s)switch(s){case"floor":return Math.floor(i);case"round":return Math.round(i);case"ceil":return Math.ceil(i)}return i}Object.defineProperty(e,"__esModule",{value:!0}),e.trim=e.filterHtml=e.htmlToArray=e.wordsRgx=e.isSpecialChar=e.stringToLetterItems=e.letterToLetterItem=e.coinFlip=e.getRandomFromRange=e.animateWithClass=e.isInRange=e.arrayOfTheSame=e.promiseWhile=e.wait=e.parseCharset=e.filterDuplicates=e.getRandom=e.deleteRandom=e.clamp=e.random=void 0,e.random=s;e.clamp=(t,e,s)=>Math.min(Math.max(e,t),s);e.deleteRandom=t=>t.splice(s(0,t.length,"floor"),1).length>0,e.getRandom=function(t){return t[s(0,t.length,"floor")]},e.filterDuplicates=function(t){const e="string"==typeof t,s=[];return new Set(t).forEach((t=>s.push(t))),e?s.join(""):s},e.parseCharset=function(t){let e;return e="string"==typeof t?t:t.length?t.join(""):Array.from(t).join(""),e};e.wait=t=>new Promise((e=>setTimeout((()=>e(t)),t))),e.promiseWhile=function(t,e){const s=()=>t()?e().then(s):Promise.resolve();return s()};e.arrayOfTheSame=(t,e)=>new Array(e).fill(t);e.isInRange=(t,e,s)=>e>=t&&e<s;e.animateWithClass=(t,e)=>{t.classList.remove(e),t.offsetWidth,t.classList.add(e)},e.getRandomFromRange=function(t,e=!0){return"number"==typeof t?t:s(...t,e?"round":void 0)};e.coinFlip=(t=.5)=>Math.random()<t;e.letterToLetterItem=t=>({value:t});e.stringToLetterItems=t=>[...t].map(e.letterToLetterItem);e.isSpecialChar=t=>["\t","\n","\r","\f","\v",""," "].includes(t);const i="(&(?:[a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});)|(<style.+?>.+?</style>|<script.+?>.+?<\/script>|<(?:!|/?[a-zA-Z]+).*?/?>)";e.wordsRgx=/(&(?:[a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});)|.\w+,*\.*"*\s?|\s+|\S+/gi,e.htmlToArray=function(t){const s=new RegExp(i,"gi"),n=[];let r,o=0;for(;r=s.exec(t);){const i=r.index,a=s.lastIndex,l=t.slice(o,i);o=a,l&&n.push(...e.stringToLetterItems(l));const h={value:r[0],type:void 0!==r[1]?"html_entity":"tag"};n.push(h)}return t.length>o&&n.push(...e.stringToLetterItems(t.slice(o))),n},e.filterHtml=function(t){const e=new RegExp(i,"g");return t.replace(e,"")},e.trim=function(t,e){if(!e||e.length>1||!t)return t;if(" "===e)return t.trim();const s=new RegExp(`${e}+`,"g");let i,n=t;for(;i=s.exec(t);){const e=i.index,r=s.lastIndex,o=r-e;0===e?n=n.substring(r):r===t.length&&(n=n.substring(n.length-o))}return n}})),c=l((function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.presets=e.glyphs=void 0,e.glyphs={nier:"一二三四五六七八九十百千上下左右中大小月日年早木林山川土空田天生花草虫犬人名女男子目耳口手足見音力気円入出立休先夕本文字学校村町森正水火玉王石竹糸貝車金雨赤青白数多少万半形太細広長点丸交光角計直線矢弱強高同親母父姉兄弟妹自友体毛頭顔首心時曜朝昼夜分週春夏秋冬今新古間方北南東西遠近前後内外場地国園谷野原里市京風雪雲池海岩星室戸家寺通門道話言答声聞語読書記紙画絵図工教晴思考知才理算作元食肉馬牛魚鳥羽鳴麦米茶色黄黒来行帰歩走止活店買売午汽弓回会組船明社切電毎合当台楽公引科歌刀番用何",full:"ABCDĐEFGHIJKLMNOPQRSTUVWXYZabcdđefghijklmnopqrstuvwxyzĄąĆćŻżŹźŃńóŁłАБВГҐДЂЕЁЄЖЗЅИІЇЙЈКЛЉМНЊОПРСТЋУЎФХЦЧЏШЩЪЫЬЭЮЯабвгґдђеёєжзѕиіїйјклљмнњопрстћуўфхцчџшщъыьэюяΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψωάΆέΈέΉίϊΐΊόΌύΰϋΎΫΏĂÂÊÔƠƯăâêôơư一二三四五六七八九十百千上下左右中大小月日年早木林山川土空田天生花草虫犬人名女男子目耳口手足見音力気円入出立休先夕本文字学校村町森正水火玉王石竹糸貝車金雨赤青白数多少万半形太細広長点丸交光角計直線矢弱強高同親母父姉兄弟妹自友体毛頭顔首心時曜朝昼夜分週春夏秋冬今新古間方北南東西遠近前後内外場地国園谷野原里市京風雪雲池海岩星室戸家寺通門道話言答声聞語読書記紙画絵図工教晴思考知才理算作元食肉馬牛魚鳥羽鳴麦米茶色黄黒来行帰歩走止活店買売午汽弓回会組船明社切電毎合当台楽公引科歌刀番用何ĂÂÊÔƠƯăâêôơư1234567890‘?’“!”(%)[#]{@}/\\&<-+÷×=>$€£¥¢:;,.*•°·…±†‡æ«»¦¯—–~˜¨_øÞ¿▬▭▮▯┐└╛░▒▓○‼⁇⁈⁉‽ℴℵℶℷℸℲ℮ℯ⅁⅂⅃⅄₠₡₢₣₤₥₦₧₨₩₪₫€₭₮₯₰₱₲₳₴₵₶₷₸₹₺₻₼₽₾₿ ",letterlike:"ABCDĐEFGHIJKLMNOPQRSTUVWXYZabcdđefghijklmnopqrstuvwxyzĄąĆćŻżŹźŃńóŁłАБВГҐДЂЕЁЄЖЗЅИІЇЙЈКЛЉМНЊОПРСТЋУЎФХЦЧЏШЩЪЫЬЭЮЯабвгґдђеёєжзѕиіїйјклљмнњопрстћуўфхцчџшщъыьэюяΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψωάΆέΈέΉίϊΐΊόΌύΰϋΎΫΏĂÂÊÔƠƯăâêôơưĂÂÊÔƠƯăâêôơư1234567890",numbers:"0123456789",zalgo:"̴̵̶̷̸̡̢̧̨̛̖̗̘̙̜̝̞̟̠̣̤̥̦̩̪̫̬̭̮̯̰̱̲̳̹̺̻̼͇͈͉͍͎̀́̂̃̄̅̆̇̈̉̊̋̌̍̎̏̐̑̒̓̔̽̾̿̀́͂̓̈́͆͊͋͌̕̚ͅ ͓͔͕͖͙͚͐͑͒͗͛ͣͤͥͦͧͨͩͪͫͬͭͮͯ͘͜͟͢͝͞͠͡͏҉",neo:"!<>-_\\/[]{}—=+*^?#________",uppercase:"1234567890QWERTYUIOPASDFGHJKLZXCVBNM#$%"},e.presets={default:{steps:[1,8],interval:[60,170],delay:[0,2e3],changeChance:.6,ghostChance:.2,maxGhosts:.2,oneAtATime:0,glyphs:e.glyphs.full+e.glyphs.zalgo,glyphsFromText:!1,fillSpace:!0,mode:"matching",html:!1,letterize:!1,endless:!1,fps:60},nier:{maxGhosts:0,ghostChance:0,changeChance:.8,steps:3,interval:10,delay:0,oneAtATime:1,glyphs:e.glyphs.nier,fillSpace:!1,glyphsFromText:!0,mode:"clear"},typewriter:{interval:[50,150],delay:0,steps:0,changeChance:0,maxGhosts:0,oneAtATime:1,glyphs:"",glyphsFromText:!1,fillSpace:!1,mode:"erase_smart"},terminal:{interval:[25,30],delay:[0,0],steps:0,changeChance:.5,maxGhosts:0,oneAtATime:1,glyphs:"",fillSpace:!1,glyphsFromText:!1,mode:"clear"},zalgo:{delay:[0,3e3],interval:[10,35],steps:[0,30],maxGhosts:4.6,changeChance:.5,ghostChance:.7,glyphs:e.glyphs.zalgo,glyphsFromText:!0,fillSpace:!1},neo:{interval:[30,100],delay:[0,1300],steps:[4,7],maxGhosts:0,ghostChance:0,changeChance:1,glyphs:e.glyphs.neo,mode:"normal"},encrypted:{interval:[50,90],delay:[0,1300],steps:[5,8],maxGhosts:0,ghostChance:0,changeChance:1,glyphs:e.glyphs.uppercase,fillSpace:!1,mode:"normal"},bitbybit:{interval:[35,65],delay:180,steps:1,maxGhosts:1,ghostChance:.1,changeChance:.7,oneAtATime:"word",glyphs:"",glyphsFromText:!0,fillSpace:!1,mode:"erase"},cosmic:{steps:[0,1],interval:30,delay:[400,2400],ghostChance:0,changeChance:.3,maxGhosts:0,glyphs:"QWERTYUIOPASDFGHJKLZXCVBNM",glyphsFromText:!1,fillSpace:!0,mode:"erase"}}})),u=l((function(t,e){Object.defineProperty(e,"__esModule",{value:!0});e.default=class{constructor(t,e){this.writer=t,this.set(e)}set(t){this.options=Object.assign(Object.assign({},c.presets.default),this.parseOptions(t)),this.updateInternal()}extend(t){this.options=Object.assign(Object.assign({},this.options),this.parseOptions(t)),this.updateInternal()}parseOptions(t){var e;return t?"string"==typeof t?null!==(e=c.presets[t])&&void 0!==e?e:{}:t:{}}updateInternal(){const{options:t}=this;this.glyphs=h.parseCharset(t.glyphs),this.setCharset(),this.space=t.fillSpace?" ":"",Number.isInteger(t.oneAtATime)?this.oneAtATime=t.oneAtATime:"word"===t.oneAtATime?this.oneAtATime="word":this.oneAtATime=t.oneAtATime?1:0}setCharset(){const{writer:t}=this;let{glyphs:e}=this;this.glyphsFromText&&(e+=h.filterDuplicates(t.previousString+(this.html?h.filterHtml(t.goalText):t.goalText))),this.charset=[...e].filter((t=>!["\t","\n","\r","\f","\v"].includes(t))),this.setMaxGhosts()}setMaxGhosts(){const{writer:{charTable:t},options:{maxGhosts:e}}=this;Number.isInteger(e)&&(this.maxGhosts=e);const{length:s}=t.filter((t=>"tag"!==t.specialType));this.maxGhosts=Math.round((s||20)*e)}getGlyph(t){const{options:e}=this;return e.genGlyph?e.genGlyph(t,this.baseGetGlyph):this.baseGetGlyph()}baseGetGlyph(){var t;return null!==(t=h.getRandom(this.charset))&&void 0!==t?t:""}get steps(){return h.getRandomFromRange(this.options.steps)}getInterval(t){const{options:e,baseGetInterval:s}=this;return e.genInterval?e.genInterval(t,s.bind(this,t)):s.call(this,t)}baseGetInterval(t){let e=h.getRandomFromRange(this.options.interval);return"whitespace"===t.specialType&&(e/=1.8),e}getDelay(t){const{options:e}=this;return e.genDelay?e.genDelay(t,this.baseGetDelay):this.baseGetDelay()}baseGetDelay(){return h.getRandomFromRange(this.options.delay)}get mode(){return this.options.mode}get html(){return this.options.html}get endless(){return this.options.endless}get fps(){return this.options.fps}get letterize(){return this.options.letterize}get ghostChance(){return this.options.ghostChance}get changeChance(){return this.options.changeChance}get glyphsFromText(){return this.options.glyphsFromText}}})),p=l((function(t,e){Object.defineProperty(e,"__esModule",{value:!0});e.default=class{constructor(t){this.nGhosts=0,this.progress={percent:0,done:0,todo:0,increase(){this.done++,this.percent=this.done/this.todo},reset(t){this.percent=0,this.done=0,this.todo=t},finish(){this.done=this.todo,this.percent=1}},this.isTyping=!1,this.isPaused=!1,this.finished=!0,this.erasing=!1,this.writer=t,this.maxGhosts=this.writer.options.maxGhosts}get ghostsInLimit(){return this.nGhosts<this.maxGhosts}play(){this.isTyping=!0,this.isPaused=!1,this.finished=!1,this.addClass(),this.erasing&&this.addClass("gw-erasing"),this.maxGhosts=this.writer.options.maxGhosts,this.writer.animator.run(),this.writer.emiter.callback("start",this.writer.goalText,this.writer.writerData)}pause(){this.isTyping=!1,this.isPaused=!0,this.removeClasses()}finish(){this.progress.finish(),this.isTyping=!1,this.finished=!0,this.removeClasses()}addClass(t="gw-writing"){h.animateWithClass(this.writer.htmlElement,t)}removeClasses(){this.writer.htmlElement.classList.remove("gw-writing","gw-erasing")}}})),d=l((function(t,e){Object.defineProperty(e,"__esModule",{value:!0});e.default=class{constructor(t){this.callbacks={start:[],step:[],finish:[]},this.writer=t}addCallback(t,e){this.callbacks[t].push(e)}removeCallback(t,e){const s=this.callbacks[t],i=s.indexOf(e);return-1!==i&&(s.splice(i,1),!0)}callback(t,...e){this.callbacks[t].forEach((t=>t(...e)))}call(t){const{writer:e}=this;e.updateString();const{writerData:s,string:i}=e;if(e.options.letterize&&e.htmlElement.setAttribute("data-gw-string",e.options.html?h.filterHtml(i):i),"step"===t)return this.callback("step",i,s);e.state.finish(),e.state.erasing||(this.callback("finish",i,s),this.emitEvent())}emitEvent(){const{htmlElement:t,writerData:e}=this.writer;"undefined"!=typeof CustomEvent&&t.dispatchEvent(new CustomEvent("gw-finished",{detail:e}))}}})),f=l((function(t,e){var s=a&&a.__awaiter||function(t,e,s,i){return new(s||(s=Promise))((function(n,r){function o(t){try{l(i.next(t))}catch(t){r(t)}}function a(t){try{l(i.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?n(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(o,a)}l((i=i.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0});function i(t,e){const{length:s}=t;t.splice(h.random(0,s,"floor"),0,e)}e.default=class{constructor(t,e,s,i="",n,r){this.ghosts=[[],[]],this.stop=!1,this.afterGlitchChance=0,this.writer=t;const{options:o}=t;this.index=r,this.l=e,this.gl=s,this.specialType=n,this.ghosts[0]=[...i],this.writer.state.nGhosts+=i.length,this.stepsLeft=o.steps,"tag"===n?this.stepsLeft=0:h.isSpecialChar(s)&&(this.specialType="whitespace"),this.afterGlitchChance=(o.ghostChance+o.changeChance)/3.7,t.options.letterize&&(this.els={ghostsBeforeEl:document.createElement("span"),letterEl:document.createElement("span"),ghostsAfterEl:document.createElement("span")},this.els.ghostsBeforeEl.className="gw-ghosts",this.els.ghostsAfterEl.className="gw-ghosts",this.els.letterEl.className="gw-letter")}get string(){const{l:t,ghosts:e}=this;return e[0].join("")+t+e[1].join("")}get finished(){const{l:t,gl:e,ghosts:s}=this;return t===e&&0===s[0].length&&0===s[1].length||"tag"===this.specialType}writeToElement(){if(!this.els)return;const{ghostsBeforeEl:t,ghostsAfterEl:e,letterEl:s,charEl:i}=this.els;s.innerHTML=this.l,t.textContent=this.ghosts[0].join(""),e.textContent=this.ghosts[1].join(""),i&&h.animateWithClass(i,"gw-changed")}set spanElement(t){this.els&&(this.els.charEl=t,this.appendChildren())}appendChildren(){var t,e;null===(e=null===(t=this.els)||void 0===t?void 0:t.charEl)||void 0===e||e.append(this.els.ghostsBeforeEl,this.els.letterEl,this.els.ghostsAfterEl),this.writeToElement()}type(){var t,e,i;return s(this,void 0,void 0,(function*(){const{options:n,state:r,emiter:o}=this.writer;if("tag"===this.specialType)return this.l=this.gl,o.call("step"),r.progress.increase(),!0;return yield h.wait(n.getDelay(this)),yield h.promiseWhile((()=>(!this.finished||n.endless)&&!r.isPaused&&!this.stop),(()=>s(this,void 0,void 0,(function*(){yield h.wait(n.getInterval(this));const t=this.string;this.step(),t!==this.string&&(o.call("step"),this.writeToElement()),!n.endless&&this.stepsLeft--})))),this.finished&&(r.progress.increase(),null===(e=null===(t=this.els)||void 0===t?void 0:t.charEl)||void 0===e||e.classList.add("gw-finished"),null===(i=this.els)||void 0===i||i.letterEl.classList.remove("gw-glitched")),this.finished}))}step(){var t,e;const{writer:s}=this;if(this.stepsLeft>0&&this.l!==this.gl||h.coinFlip(this.afterGlitchChance)&&"whitespace"!==this.specialType||s.options.endless){const{ghostChance:e,changeChance:i}=s.options;h.coinFlip(e)&&(s.state.ghostsInLimit?this.addGhost():this.removeGhost()),h.coinFlip(i)&&(null===(t=this.els)||void 0===t||t.letterEl.classList.add("gw-glitched"),this.l=s.options.getGlyph(this))}else this.finished||(null===(e=this.els)||void 0===e||e.letterEl.classList.remove("gw-glitched"),this.l=this.gl,this.removeGhost())}addGhost(){const{writer:t,ghosts:e}=this,s=t.options.getGlyph(this);t.state.nGhosts++,h.coinFlip()?i(e[0],s):i(e[1],s)}removeGhost(){const{writer:t,ghosts:e}=this;(h.coinFlip()&&e[0].length>0?h.deleteRandom(e[0]):h.deleteRandom(e[1]))&&t.state.nGhosts--}}})),g=l((function(t,e){var s=a&&a.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const i=s(f);function n(t){const e=Math.min(Math.ceil(this.options.maxGhosts/2),5),s=o.call(this,t);let i=-1;s.forEach(((s,n)=>{if(i++,"tag"===s.type)return i--,void l.call(this,n,"",s);const r=""!==s.value?t.indexOf(s.value,i):-1;if(-1!==r&&r-i<=e){const e=t.substring(i,r);l.call(this,n,s.value,s,e),i=r}else l.call(this,n,t[i],s)})),c(this.charTable,s.length)}function r(t){const e=o.call(this,t);let s=-1;e.forEach(((e,i)=>{if(s++,"tag"===e.type)return s--,void l.call(this,i,"",e);l.call(this,i,t[s],e)})),c(this.charTable,e.length)}function o(t){const{options:e,goalText:s}=this,i=e.html?h.htmlToArray(s):h.stringToLetterItems(s),n=Math.max(0,t.length-i.length);if(e.oneAtATime)return i.concat(h.stringToLetterItems(h.arrayOfTheSame("",n)));const r=Math.ceil(n/2),o=Math.floor(n/2);return h.stringToLetterItems(h.arrayOfTheSame("",r)).concat(i,h.stringToLetterItems(h.arrayOfTheSame("",o)))}function l(t,e,s,n){const{charTable:r,options:o}=this;r.push(new i.default(this,null!=e?e:"",s.value||o.space,n,s.type,t))}function c(t,e){t.splice(e,t.length-e)}e.default=function(){const{charTable:t,options:e}=this,s="clear"===e.mode&&this.state.finished?"":this.previousString;t.forEach((t=>t.stop=!0)),this.charTable=[],"matching"===e.mode?n.call(this,s):r.call(this,s)}})),m=l((function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(){if(!this.options.letterize)return;const t=this.charTable.map((({specialType:t,gl:e})=>"tag"===t?e:'<span class="gw-char"></span>')).join("");this.htmlElement.innerHTML=t;const e=this.htmlElement.querySelectorAll("span.gw-char");let s=0;this.charTable.forEach((t=>{"tag"!==t.specialType&&(t.spanElement=e[s],s++)}))}})),y=l((function(t,e){var s=a&&a.__awaiter||function(t,e,s,i){return new(s||(s=Promise))((function(n,r){function o(t){try{l(i.next(t))}catch(t){r(t)}}function a(t){try{l(i.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?n(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(o,a)}l((i=i.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){const{charTable:e,state:i}=this,n=[];let r;r=e.filter(((t,e)=>"tag"!==t.specialType&&"html_entity"!==t.specialType&&(n.push(e),!0))).map((t=>t.gl)).join("").match(h.wordsRgx);const o=[];{let t=-1,s=-1,i=-1;const a=()=>o[o.length-1];null==r||r.forEach((r=>{o.push([]),[...r].forEach((()=>{if(t++,s=n[t],i++,i!==s){for(let t=i;t<s;t++)a().push(e[t]);i=s}a().push(e[s])}))})),o.length||o.push([]);for(let t=s+1;t<e.length;t++)a().push(e[t])}o.reverse();let a=!0,l=!1;const c=()=>s(this,void 0,void 0,(function*(){var t;const e=o.pop();if(!e)return l=!0;const s=e.map((t=>t.type()));a=null!==(t=(yield Promise.all(s)).every((t=>t)))&&void 0!==t&&t}));t.push((()=>s(this,void 0,void 0,(function*(){return yield h.promiseWhile((()=>!l&&a&&!i.isPaused),c),l&&a&&!i.isPaused})))())}})),v=l((function(t,e){var s=a&&a.__awaiter||function(t,e,s,i){return new(s||(s=Promise))((function(n,r){function o(t){try{l(i.next(t))}catch(t){r(t)}}function a(t){try{l(i.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?n(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(o,a)}l((i=i.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){var i;const{charTable:n,state:r,options:o}=this,a=null!==(i=null==e?void 0:e.reverse)&&void 0!==i&&i?[...n]:[...n].reverse(),l=()=>s(this,void 0,void 0,(function*(){let t=!0,e=!1;return yield h.promiseWhile((()=>!e&&t&&!r.isPaused),(()=>s(this,void 0,void 0,(function*(){var s;const i=a.pop();i?t=null!==(s=yield i.type())&&void 0!==s&&s:e=!0})))),e&&t&&!r.isPaused}));for(let e=0;e<o.oneAtATime;e++)t.push(l())}})),w=l((function(t,e){Object.defineProperty(e,"__esModule",{value:!0});e.default=class{constructor(t){this.last=0,this.rate=16,this.running=!1,this.writer=t}run(){this.running||this.writer.options.letterize||(this.rate=Math.floor(1e3/this.writer.options.fps),this.running=!0,requestAnimationFrame(this.frame.bind(this)))}frame(t){return this.writer.state.isTyping?(this.last||(this.last=t),t-this.last<this.rate||(this.animate.call(this),this.last=t),requestAnimationFrame(this.frame.bind(this))):(this.animate.call(this),this.running=!1)}animate(){const{htmlElement:t,string:e}=this.writer;this.writer.options.html?t.innerHTML=e:t.textContent=e,t.setAttribute("data-gw-string",this.writer.options.html?h.filterHtml(e):e)}}})),b=l((function(t,e){var s=a&&a.__awaiter||function(t,e,s,i){return new(s||(s=Promise))((function(n,r){function o(t){try{l(i.next(t))}catch(t){r(t)}}function a(t){try{l(i.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?n(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(o,a)}l((i=i.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0});e.default=class{constructor(t,e,s=800,i=!1){if(this.isStopped=!1,this.isLooping=!1,this.loopInterval=0,this.index=-1,this.writer=t,this.interval=s,Array.isArray(e))this.texts=e;else{let t;t="object"==typeof e?e:document.querySelector(e),this.texts=[],null==t||t.childNodes.forEach((t=>{const{tagName:e,innerHTML:s}=t;"P"===e&&void 0!==s&&this.texts.push(s)}))}"boolean"==typeof i?this.isLooping=i:"function"==typeof i?this.endCallback=i:(this.isLooping=!0,this.loopInterval=i),this.loop()}stop(){this.isStopped=!0}resume(){this.index--,this.isStopped=!1,this.writer.state.isPaused=!1,this.loop()}loop(){var t;return s(this,void 0,void 0,(function*(){if(!this.texts.length)return;if(this.index++,this.index>=this.texts.length){if(!this.isLooping)return null===(t=this.endCallback)||void 0===t?void 0:t.call(this,this.writer.string,this.writer.getWriterData("SUCCESS","The queue has reached it's end."));yield h.wait(this.loopInterval),this.index=0}if(this.isStopped||this.writer.state.isPaused)return;const e=yield this.writer.manageWriting(this.texts[this.index]);"SUCCESS"!==(null==e?void 0:e.status)||this.writer.state.isPaused||(yield h.wait(this.interval),this.loop())}))}}})),T=l((function(t,e){var s=a&&a.__awaiter||function(t,e,s,i){return new(s||(s=Promise))((function(n,r){function o(t){try{l(i.next(t))}catch(t){r(t)}}function a(t){try{l(i.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?n(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(o,a)}l((i=i.apply(t,e||[])).next())}))},i=a&&a.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.wait=e.glyphs=e.presets=e.create=e.queueWrite=e.write=void 0;const n=i(u),r=i(p),o=i(d);Object.defineProperty(e,"wait",{enumerable:!0,get:function(){return h.wait}}),Object.defineProperty(e,"presets",{enumerable:!0,get:function(){return c.presets}}),Object.defineProperty(e,"glyphs",{enumerable:!0,get:function(){return c.glyphs}});const l=i(g),f=i(m),T=i(y),x=i(v),C=i(w),E=i(b);class S{constructor(t,e,s){var i;this.charTable=[],this.goalText="",this.lastText="",this.string="",this.htmlElement=t?"string"==typeof t?null!==(i=document.querySelector(t))&&void 0!==i?i:document.createElement("span"):t:document.createElement("span"),this.htmlElement.$writer=this,this.options=new n.default(this,e),this.state=new r.default(this),this.emiter=new o.default(this),s&&this.emiter.addCallback("finish",s),this.animator=new C.default(this),this.string=this.previousString}updateString(){this.string=this.charTable.map((t=>t.string)).join("")}get previousString(){let t=this.htmlElement.textContent;return"string"!=typeof t&&(t=this.options.html?h.filterHtml(this.string):this.string),t=t.trim(),t}get writerData(){const{options:t,state:e,string:s}=this;return{string:s,writer:this,options:t,state:e}}write(t){return s(this,void 0,void 0,(function*(){return this.queue&&(this.queue.stop(),delete this.queue),this.manageWriting(t)}))}queueWrite(t,e,s){this.queue&&(this.queue.stop(),delete this.queue),this.queue=new E.default(this,t,e,s)}add(t){return s(this,void 0,void 0,(function*(){const{previousString:e}=this;return this.write(e+t)}))}remove(t){return s(this,void 0,void 0,(function*(){const{previousString:e}=this,s=Array.from(e);return s.splice(-t),this.write(s.join(""))}))}play(){return s(this,void 0,void 0,(function*(){return this.state.isPaused?this.queue?(this.queue.resume(),this.getWriterData("SUCCESS","The queue was resumed")):this.manageWriting(null):this.getWriterData("ERROR","The writer isn't paused.")}))}pause(){this.state.pause()}endless(t){this.options.extend({endless:t})}addCallback(t,e){return this.emiter.addCallback(t,e),this}removeCallback(t,e){return this.emiter.removeCallback(t,e),this}manageWriting(t){return s(this,void 0,void 0,(function*(){if(null!==t&&(this.lastText=t),["erase_smart","erase"].includes(this.options.mode)&&(this.state.finished||this.state.erasing)){this.state.erasing=!0;const t=this.genGoalStringToErase(this.lastText);if(this.preparePropertiesBeforeWrite(t),yield this.playChT({reverse:0!==this.options.oneAtATime}),!this.state.finished)return this.getWriterData("ERROR","Erasing did not finish.");this.state.erasing=!1}return this.preparePropertiesBeforeWrite(this.lastText),this.pause(),this.playChT()}))}preparePropertiesBeforeWrite(t){this.goalText=t,this.state.nGhosts=0,this.options.setCharset(),l.default.call(this),this.state.progress.reset(this.charTable.length),f.default.call(this)}playChT(t){return s(this,void 0,void 0,(function*(){const e=[],{charTable:s,state:i,options:n}=this;if(i.isTyping)return this.getWriterData("ERROR","The writer is already typing.");i.play(),n.oneAtATime>0?x.default.call(this,e,t):"word"===n.oneAtATime?T.default.call(this,e):s.forEach((t=>e.push(t.type())));try{const t=(yield Promise.all(e)).every((t=>t));return this.returnResult(t)}catch(t){return this.getWriterData("ERROR","Writer encountered an error.",t)}}))}returnResult(t){return t?this.emiter.call("finish"):this.emiter.call("step"),t?this.getWriterData("SUCCESS","The writer finished typing."):this.getWriterData("ERROR","Writer failed to finish typing.")}getWriterData(t,e,s){const{writerData:i}=this;return Object.assign(Object.assign({},i),{status:t,message:e,error:s})}genGoalStringToErase(t){var e;const{previousString:s}=this;let i="";if("erase_smart"===this.options.mode)for(let n=0;n<t.length;n++){const r=t[n],o=null!==(e=s[n])&&void 0!==e?e:"";if(r!==o)break;i+=o}const n=Math.max(t.length-i.length,0);return n>0&&" "===this.options.space&&(i=i.padEnd(n+i.length," ")),i}}e.default=S,e.write=function(t,e,i,n,r){return s(this,void 0,void 0,(function*(){const s=new S(e,i,r);return n&&s.addCallback("step",n),s.write(t)}))},e.queueWrite=function(t,e,s,i,n,r,o){const a=new S(e,s,o);return r&&a.addCallback("step",r),a.queueWrite(t,i,n),a};e.create=(t,e,s)=>new S(t,e,s)}));var x=t.defineComponent({name:"VueGlitchedWriter",props:{text:{type:[String,Array],required:!0},pause:{type:Boolean,default:!1},preset:{type:String,default:"default"},options:{type:Object,default:function(){}},queue:{type:Object,default:function(){}},silent:{type:Boolean,default:!0},tag:{type:String,default:"span"}},setup:function(e,n){var r=n.emit,o=n.attrs,a=t.ref(null),l=t.ref(null),h=t.computed((function(){var t;return null!==(t=T.presets[e.preset])&&void 0!==t?t:{}})),c=void 0!==o.appear||"object"===i(e.text)&&e.text.length>0,u=t.computed((function(){var t;return"number"==typeof(null===(t=e.queue)||void 0===t?void 0:t.interval)?e.queue.interval:void 0})),p=t.computed((function(){var t;return["number","boolean","function"].includes(i(null===(t=e.queue)||void 0===t?void 0:t.loop))?e.queue.loop:void 0})),d=t.computed((function(){return s(s({},h.value),e.options)}));function f(){if(!e.pause)if("string"==typeof e.text)a.value.write(e.text);else{var t=e.text.map((function(t){return String(t)}));a.value.queueWrite(t,u.value,p.value)}}t.watch(d,(function(t){return a.value.options.set(t)})),t.watch((function(){return e.text}),f),t.watch((function(){return e.pause}),(function(t){return t?a.value.pause():a.value.play()})),t.onMounted((function(){a.value=T.create(l.value,d.value),a.value.addCallback("step",(function(t,e){return r("step",t,e)})),a.value.addCallback("start",(function(t,e){return r("start",t,e)})),a.value.addCallback("finish",(function(t,e){return r("finish",t,e)})),c&&f()}));var g="";if(void 0===o.appear){var m,y="string"==typeof e.text?e.text:String(null!==(m=e.text[0])&&void 0!==m?m:"");g=d.value.html?y:function(t){var e=document.createTextNode(t),s=document.createElement("p");return s.appendChild(e),s.innerHTML}(y)}return{writer:a,element:l,initialText:g}}});x.render=function(e,s,i,n,r,o){return t.openBlock(),t.createBlock(t.resolveDynamicComponent(e.tag),{ref:"element",innerHTML:e.initialText,class:["glitched-writer",{"gw-paused":e.pause}]},null,8,["innerHTML","class"])};var C=function(){var t=x;return t.install=function(e){e.component("VueGlitchedWriter",t)},t}(),E=Object.freeze({__proto__:null,default:C,presets:T.presets,wait:T.wait,glyphs:T.glyphs,CustomOptions:T.CustomOptions,Callback:T.Callback,GlitchedWriter:T,WriterDataResponse:T.WriterDataResponse});return Object.entries(E).forEach((function(t){var e=r(t,2),s=e[0],i=e[1];"default"!==s&&(C[s]=i)})),C}(Vue);