glitched-writer
Advanced tools
Comparing version 2.0.18 to 2.0.19
@@ -248,3 +248,6 @@ "use strict"; | ||
? utils_1.htmlToArray(goal) | ||
: utils_1.stringToLetterItems(goal), diff = Math.max(0, previousString.length - goalArray.length), nBefore = Math.ceil(diff / 2), nAfter = Math.floor(diff / 2); | ||
: utils_1.stringToLetterItems(goal), diff = Math.max(0, previousString.length - goalArray.length); | ||
if (this.options.oneAtATime) | ||
return goalArray.concat(utils_1.stringToLetterItems(utils_1.arrayOfTheSame('', diff))); | ||
const nBefore = Math.ceil(diff / 2), nAfter = Math.floor(diff / 2); | ||
return utils_1.stringToLetterItems(utils_1.arrayOfTheSame('', nBefore)).concat(goalArray, utils_1.stringToLetterItems(utils_1.arrayOfTheSame('', nAfter))); | ||
@@ -251,0 +254,0 @@ } |
@@ -239,3 +239,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
? htmlToArray(goal) | ||
: stringToLetterItems(goal), diff = Math.max(0, previousString.length - goalArray.length), nBefore = Math.ceil(diff / 2), nAfter = Math.floor(diff / 2); | ||
: stringToLetterItems(goal), diff = Math.max(0, previousString.length - goalArray.length); | ||
if (this.options.oneAtATime) | ||
return goalArray.concat(stringToLetterItems(arrayOfTheSame('', diff))); | ||
const nBefore = Math.ceil(diff / 2), nAfter = Math.floor(diff / 2); | ||
return stringToLetterItems(arrayOfTheSame('', nBefore)).concat(goalArray, stringToLetterItems(arrayOfTheSame('', nAfter))); | ||
@@ -242,0 +245,0 @@ } |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["glitched-writer"]=e():t["glitched-writer"]=e()}(self,(function(){return(()=>{"use strict";var t={d:(e,s)=>{for(var i in s)t.o(s,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:s[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},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}t.r(e),t.d(e,{default:()=>E,glitchWrite:()=>S,glyphs:()=>p,presets:()=>d,wait:()=>n});const i=t=>t.splice(s(0,t.length,"floor"),1).length>0,n=t=>new Promise((e=>setTimeout((()=>e(t)),t)));function r(t,e){const s=()=>t()?e().then(s):Promise.resolve();return s()}const h=(t,e)=>new Array(e).fill(t);function o(t,e=!0){return"number"==typeof t?t:s(...t,e?"round":void 0)}const l=(t=.5)=>Math.random()<t,a=t=>({value:t}),g=t=>[...t].map(a),c="(&#?[0-9a-zA-Z]{2,6};)|(<style.+?>.+?</style>|<script.+?>.+?<\/script>|<(?:!|/?[a-zA-Z]+).*?/?>)";function u(t){const e=new RegExp(c,"g");return t.replace(e,"")}const p={nier:"一二三四五六七八九十百千上下左右中大小月日年早木林山川土空田天生花草虫犬人名女男子目耳口手足見音力気円入出立休先夕本文字学校村町森正水火玉王石竹糸貝車金雨赤青白数多少万半形太細広長点丸交光角計直線矢弱強高同親母父姉兄弟妹自友体毛頭顔首心時曜朝昼夜分週春夏秋冬今新古間方北南東西遠近前後内外場地国園谷野原里市京風雪雲池海岩星室戸家寺通門道話言答声聞語読書記紙画絵図工教晴思考知才理算作元食肉馬牛魚鳥羽鳴麦米茶色黄黒来行帰歩走止活店買売午汽弓回会組船明社切電毎合当台楽公引科歌刀番用何",full:"ABCDĐEFGHIJKLMNOPQRSTUVWXYZabcdđefghijklmnopqrstuvwxyzĄąĆ毿ŹźŃńóŁłАБВГҐДЂЕЁЄЖЗЅИІЇЙЈКЛЉМНЊОПРСТЋУЎФХЦЧЏШЩЪЫЬЭЮЯабвгґдђеёєжзѕиіїйјклљмнњопрстћуўфхцчџшщъыьэюяΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψωάΆέΈέΉίϊΐΊόΌύΰϋΎΫΏĂÂÊÔƠƯăâêôơư一二三四五六七八九十百千上下左右中大小月日年早木林山川土空田天生花草虫犬人名女男子目耳口手足見音力気円入出立休先夕本文字学校村町森正水火玉王石竹糸貝車金雨赤青白数多少万半形太細広長点丸交光角計直線矢弱強高同親母父姉兄弟妹自友体毛頭顔首心時曜朝昼夜分週春夏秋冬今新古間方北南東西遠近前後内外場地国園谷野原里市京風雪雲池海岩星室戸家寺通門道話言答声聞語読書記紙画絵図工教晴思考知才理算作元食肉馬牛魚鳥羽鳴麦米茶色黄黒来行帰歩走止活店買売午汽弓回会組船明社切電毎合当台楽公引科歌刀番用何ĂÂÊÔƠƯăâêôơư1234567890‘?’“!”(%)[#]{@}/\\&<-+÷×=>$€£¥¢:;,.*•°·…±†‡æ«»¦¯—–~˜¨_øÞ¿▬▭▮▯┐└╛░▒▓○‼⁇⁈⁉‽ℴℵℶℷℸℲ℮ℯ⅁⅂⅃⅄₠₡₢₣₤₥₦₧₨₩₪₫€₭₮₯₰₱₲₳₴₵₶₷₸₹₺₻₼₽₾₿ ",letterlike:"ABCDĐEFGHIJKLMNOPQRSTUVWXYZabcdđefghijklmnopqrstuvwxyzĄąĆ毿ŹźŃńóŁłАБВГҐДЂЕЁЄЖЗЅИІЇЙЈКЛЉМНЊОПРСТЋУЎФХЦЧЏШЩЪЫЬЭЮЯабвгґдђеёєжзѕиіїйјклљмнњопрстћуўфхцчџшщъыьэюяΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψωάΆέΈέΉίϊΐΊόΌύΰϋΎΫΏĂÂÊÔƠƯăâêôơưĂÂÊÔƠƯăâêôơư1234567890",zalgo:"̴̵̶̷̸̡̢̧̨̛̖̗̘̙̜̝̞̟̠̣̤̥̦̩̪̫̬̭̮̯̰̱̲̳̹̺̻̼͇͈͉͍͎̀́̂̃̄̅̆̇̈̉̊̋̌̍̎̏̐̑̒̓̔̽̾̿̀́͂̓̈́͆͊͋͌̕̚ͅ ͓͔͕͖͙͚͐͑͒͗͛ͣͤͥͦͧͨͩͪͫͬͭͮͯ͘͜͟͢͝͞͠͡͏҉",neo:"!<>-_\\/[]{}—=+*^?#________",uppercase:"1234567890QWERTYUIOPASDFGHJKLZXCVBNM#$%"},d={default:{steps:[1,8],interval:[60,170],initialDelay:[0,2e3],changeChance:.6,ghostChance:.2,maxGhosts:.2,glyphs:p.full+p.zalgo,glyphsFromString:!1,oneAtATime:!1,html:!1,fillSpace:!0,letterize:!1,endless:!1,startFrom:"matching"},nier:{maxGhosts:0,ghostChance:0,changeChance:.8,steps:2,interval:10,initialDelay:0,glyphs:p.nier,oneAtATime:!0,startFrom:"erase",glyphsFromString:!0},typewriter:{interval:[40,100],initialDelay:[0,0],steps:[0,1],changeChance:1,maxGhosts:0,glyphs:"",glyphsFromString:!0,oneAtATime:!0,startFrom:"erase"},terminal:{interval:[25,30],initialDelay:[0,0],steps:0,changeChance:.5,maxGhosts:0,glyphs:"",oneAtATime:!0,fillSpace:!1,glyphsFromString:!1,startFrom:"erase"},zalgo:{initialDelay:[0,3e3],interval:[10,35],steps:[0,30],maxGhosts:4.6,changeChance:.5,ghostChance:.7,glyphs:p.zalgo,glyphsFromString:!0,fillSpace:!1},neo:{glyphs:p.neo,maxGhosts:0,ghostChance:0,changeChance:1,interval:[30,100],initialDelay:[0,1300],steps:[4,7],startFrom:"previous",letterize:!0},encrypted:{glyphs:p.uppercase,maxGhosts:0,ghostChance:0,changeChance:1,interval:[50,90],initialDelay:[0,1300],steps:[5,8],startFrom:"previous",fillSpace:!1,letterize:!0}};class f{constructor(t,e){var s,i,n,r,h,o,l,a,g,c,u,p,f,m;"string"==typeof e&&(e=d[e]),e||(e={}),this.steps=null!==(s=e.steps)&&void 0!==s?s:d.default.steps,this.interval=null!==(i=e.interval)&&void 0!==i?i:d.default.interval,this.initialDelay=null!==(n=e.initialDelay)&&void 0!==n?n:d.default.initialDelay,this.changeChance=null!==(r=e.changeChance)&&void 0!==r?r:d.default.changeChance,this.ghostChance=null!==(h=e.ghostChance)&&void 0!==h?h:d.default.ghostChance,this.maxGhosts=null!==(o=e.maxGhosts)&&void 0!==o?o:d.default.maxGhosts,this.glyphs=null!==(l=function(t){if(void 0===t)return;let e;return e="string"==typeof t?t:t.length?t.join(""):Array.from(t).join(""),e}(e.glyphs))&&void 0!==l?l:d.default.glyphs,this.glyphsFromString=null!==(a=e.glyphsFromString)&&void 0!==a?a:d.default.glyphsFromString,this.ghostCharset=[...this.glyphs],this.oneAtATime=null!==(g=e.oneAtATime)&&void 0!==g?g:d.default.oneAtATime,this.html=null!==(c=e.html)&&void 0!==c?c:d.default.html,this.letterize=null!==(u=e.letterize)&&void 0!==u?u:d.default.letterize,this.endless=null!==(p=e.endless)&&void 0!==p?p:d.default.endless,"undefined"==typeof document&&(this.letterize=!1),this.startFrom=null!==(f=e.startFrom)&&void 0!==f?f:d.default.startFrom,this.writer=t,this.space=(null!==(m=e.fillSpace)&&void 0!==m?m:d.default.fillSpace)?" ":""}get stepsLeft(){return o(this.steps)}get genInterval(){return o(this.interval)}get genInitDelay(){return o(this.initialDelay)}get genMaxGhosts(){if(Number.isInteger(this.maxGhosts))return this.maxGhosts;let t;return t=this.writer.options.html?u(this.writer.goalString).length:this.writer.goalString.length,Math.round((t||20)*this.maxGhosts)}get genGhost(){var t,e;return null!==(t=(e=this.ghostCharset)[s(0,e.length,"floor")])&&void 0!==t?t:""}setCharset(){let t=this.glyphs;this.glyphsFromString&&(t+=function(t){const e="string"==typeof t,s=[];return new Set(t).forEach((t=>s.push(t))),e?s.join(""):s}(this.writer.previousString+(this.writer.options.html?u(this.writer.goalString):this.writer.goalString))),this.ghostCharset=[...t].filter((t=>!["\t","\n","\r","\f","\v"].includes(t)))}}class m{constructor(t){this.nGhosts=0,this.isTyping=!1,this.isPaused=!1,this.finished=!1,this.writer=t,this.maxGhosts=this.writer.options.genMaxGhosts}get ghostsInLimit(){return this.nGhosts<this.maxGhosts}play(){this.isTyping=!0,this.isPaused=!1,this.finished=!1,this.toggleClass(!0),this.maxGhosts=this.writer.options.genMaxGhosts}pause(){this.isTyping=!1,this.isPaused=!0,this.toggleClass(!1)}finish(){this.isTyping=!1,this.finished=!0,this.toggleClass(!1)}toggleClass(t){const e=this.writer.htmlElement,s="gw-writing";e&&(t?((t,e)=>{t.classList.remove(e),t.offsetWidth,t.classList.add(e)})(e,s):e.classList.remove(s))}}var v=function(t,e,s,i){return new(s||(s=Promise))((function(n,r){function h(t){try{l(i.next(t))}catch(t){r(t)}}function o(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(h,o)}l((i=i.apply(t,e||[])).next())}))};class y{constructor(t,e,s,i="",n=!1){this.ghostsBefore=[],this.ghostsAfter=[],this.stop=!1,this.isTag=!1,this.isWhitespace=!1,this.afterGlitchChance=0,this.writer=t,this.setProps(e,s,i,n),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")}setProps(t,e,s="",i=!1){const{options:n}=this.writer;this.l=t,this.gl=e,this.isTag=i,this.ghostsBefore=[...s],this.writer.state.nGhosts+=s.length,this.stepsLeft=n.stepsLeft,i&&(this.stepsLeft=0),this.isWhitespace=(t=>["\t","\n","\r","\f","\v",""," "].includes(t))(e),this.afterGlitchChance=(n.ghostChance+n.changeChance)/3.7}reset(t,e,s="",i=!1){this.setProps(t,e,s,i),this.els&&(this.els.letterEl.className="gw-letter")}get string(){const{l:t,ghostsAfter:e,ghostsBefore:s}=this;return s.join("")+t+e.join("")}get finished(){const{l:t,gl:e,ghostsBefore:s,ghostsAfter:i}=this;return t===e&&0===s.length&&0===i.length||this.isTag}get interval(){let t=this.writer.options.genInterval;return this.isWhitespace&&(t/=2),t}writeToElement(){if(!this.els)return;const{ghostsBeforeEl:t,ghostsAfterEl:e,letterEl:s}=this.els;s.innerHTML=this.l,t.textContent=this.ghostsBefore.join(""),e.textContent=this.ghostsAfter.join("")}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,s;return v(this,void 0,void 0,(function*(){const{writer:i}=this;return this.isTag?(this.l=this.gl,i.emiter.call("step"),!0):(yield n(i.options.genInitDelay),yield r((()=>(!this.finished||i.options.endless)&&!i.state.isPaused&&!this.stop),(()=>v(this,void 0,void 0,(function*(){yield n(this.interval);const t=this.string;this.step(),t!==this.string&&(i.emiter.call("step"),this.writeToElement()),!i.options.endless&&this.stepsLeft--})))),this.finished&&(null===(e=null===(t=this.els)||void 0===t?void 0:t.charEl)||void 0===e||e.classList.add("gw-finished"),null===(s=this.els)||void 0===s||s.letterEl.classList.remove("gw-glitched")),this.finished)}))}step(){var t,e;const{writer:s}=this;if(this.stepsLeft>0&&this.l!==this.gl||l(this.afterGlitchChance)&&!this.isWhitespace||s.options.endless){const{ghostChance:e,changeChance:i}=s.options;l(e)&&(s.state.ghostsInLimit?this.addGhost():this.removeGhost()),l(i)&&(null===(t=this.els)||void 0===t||t.letterEl.classList.add("gw-glitched"),this.l=s.options.genGhost)}else this.finished||(null===(e=this.els)||void 0===e||e.letterEl.classList.remove("gw-glitched"),this.l=this.gl,this.removeGhost())}addGhost(){const t=this.writer.options.genGhost;this.writer.state.nGhosts++,l()?w(this.ghostsBefore,t):w(this.ghostsAfter,t)}removeGhost(){(l()&&this.ghostsBefore.length>0?i(this.ghostsBefore):i(this.ghostsAfter))&&this.writer.state.nGhosts--}}function w(t,e){const{length:i}=t;t.splice(s(0,i,"floor"),0,e)}var C=function(t,e,s,i){return new(s||(s=Promise))((function(n,r){function h(t){try{l(i.next(t))}catch(t){r(t)}}function o(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(h,o)}l((i=i.apply(t,e||[])).next())}))};class E{constructor(t,e,s,i){var n;this.charTable=[],this.goalString="",this.string="","string"==typeof t?"undefined"!=typeof document&&(this.htmlElement=null!==(n=document.querySelector(t))&&void 0!==n?n:void 0):this.htmlElement=null!=t?t:void 0,this.options=new f(this,e),this.state=new m(this),this.emiter=new class{constructor(t,e,s){this.onStepCallback=e,this.onFinishCallback=s,this.writer=t}call(t){var e,s;this.writer.updateString();const{htmlElement:i,writerData:n,string:r}=this.writer;i&&!this.writer.options.letterize&&(this.writer.options.html?i.innerHTML=r:i.textContent=r),null==i||i.setAttribute("data-gw-string",this.writer.options.html?u(r):r),"finish"===t?(this.writer.state.finish(),null===(e=this.onFinishCallback)||void 0===e||e.call(this,r,n),this.emitEvent()):null===(s=this.onStepCallback)||void 0===s||s.call(this,r,n)}emitEvent(){const{htmlElement:t,writerData:e}=this.writer;t&&"undefined"!=typeof CustomEvent&&(null==t||t.dispatchEvent(new CustomEvent("gw-finished",{detail:e})))}}(this,s,i),this.string=this.previousString}updateString(){this.string=this.charTable.map((t=>t.string)).join("")}get previousString(){var t;let e=null===(t=this.htmlElement)||void 0===t?void 0:t.textContent;return"string"!=typeof e&&(e=this.options.html?u(this.string):this.string),e=e.trim(),e}get writerData(){const{options:t,state:e,string:s}=this;return{string:s,writer:this,options:t,state:e}}write(t,e){return C(this,void 0,void 0,(function*(){return"erase"!==this.options.startFrom||(null==e?void 0:e.erase)||(yield this.write(this.genGoalStringToErase(t),{erase:!0})),this.goalString=t,this.state.nGhosts=0,this.options.setCharset(),"matching"===this.options.startFrom?this.createMatchingCharTable():this.createPreviousCharTable(),this.letterize(),this.pause(),this.play({reverse:this.options.oneAtATime&&(null==e?void 0:e.erase)})}))}add(t){return C(this,void 0,void 0,(function*(){const{previousString:e}=this;return this.write(e+t)}))}remove(t){return C(this,void 0,void 0,(function*(){const{previousString:e}=this,s=Array.from(e);return s.splice(-t),this.write(s.join(""),{erase:!0})}))}play(t){var e;return C(this,void 0,void 0,(function*(){const s=[],{charTable:i}=this,{length:n}=i;if(this.state.isTyping)return this.getWriterData("ERROR",`The writer is already typing "${this.goalString}".`);if(this.state.play(),this.options.oneAtATime){const s=null!==(e=null==t?void 0:t.reverse)&&void 0!==e&&e;let h=s?n-1:0,o=!0;const l=()=>C(this,void 0,void 0,(function*(){o=yield i[h].type(),s?h--:h++}));return yield r((()=>{return(t=h)>=0&&t<n&&o&&!this.state.isPaused;var t}),l),this.returnResult(o)}i.forEach((t=>s.push(t.type())));try{const t=(yield Promise.all(s)).every((t=>t));return this.returnResult(t)}catch(t){return this.getWriterData("ERROR","Writer encountered an error.",t)}}))}pause(){this.state.pause()}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.")}createMatchingCharTable(){const{goalStringArray:t,previousString:e}=this,s=Math.min(Math.ceil(this.options.genMaxGhosts/2),5);let i=-1;t.forEach(((t,n)=>{if(i++,"tag"===t.type)return i--,void this.setChar(n,"",t);const r=""!==t.value?e.indexOf(t.value,i):-1;if(-1!==r&&r-i<=s){const s=e.substring(i,r);this.setChar(n,t.value,t,s),i=r}else this.setChar(n,e[i],t)})),this.removeExtraChars(t.length)}createPreviousCharTable(){const{goalStringArray:t,previousString:e}=this;let s=-1;t.forEach(((t,i)=>{if(s++,"tag"===t.type)return s--,void this.setChar(i,"",t);this.setChar(i,e[s],t)})),this.removeExtraChars(t.length)}letterize(){if(!this.options.letterize||!this.htmlElement)return;const t=this.charTable.map((({isTag:t,gl:e})=>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=>{t.isTag||(t.spanElement=e[s],s++)}))}removeExtraChars(t){const{charTable:e}=this;e.splice(t,e.length-t)}setChar(t,e,s,i){const{charTable:n}=this,r=n[t];r?r.reset(null!=e?e:"",s.value||this.options.space,i,"tag"===s.type):n.push(new y(this,null!=e?e:"",s.value||this.options.space,i,"tag"===s.type))}get goalStringArray(){const{goalString:t,options:e,previousString:s}=this,i=e.html?function(t){const e=new RegExp(c,"g"),s=[];let i,n=0;for(;i=e.exec(t);){const r=i.index,h=e.lastIndex,o=t.slice(n,r);n=h,o&&s.push(...g(o));const l={value:i[0],type:void 0!==i[1]?"html_entity":"tag"};s.push(l)}return t.length>n&&s.push(...g(t.slice(n))),s}(t):g(t),n=Math.max(0,s.length-i.length),r=Math.ceil(n/2),o=Math.floor(n/2);return g(h("",r)).concat(i,g(h("",o)))}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="";for(let n=0;n<t.length;n++){const r=t[n],h=null!==(e=s[n])&&void 0!==e?e:"";if(r!==h)break;i+=h}const n=Math.max(t.length-i.length,0);return n>0&&" "===this.options.space&&(i=i.padEnd(n+i.length," ")),i}}function S(t,e,s,i,n){return C(this,void 0,void 0,(function*(){return new E(e,s,i,n).write(t)}))}return e})()})); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["glitched-writer"]=e():t["glitched-writer"]=e()}(self,(function(){return(()=>{"use strict";var t={d:(e,s)=>{for(var i in s)t.o(s,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:s[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},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}t.r(e),t.d(e,{default:()=>E,glitchWrite:()=>S,glyphs:()=>p,presets:()=>d,wait:()=>n});const i=t=>t.splice(s(0,t.length,"floor"),1).length>0,n=t=>new Promise((e=>setTimeout((()=>e(t)),t)));function r(t,e){const s=()=>t()?e().then(s):Promise.resolve();return s()}const h=(t,e)=>new Array(e).fill(t);function o(t,e=!0){return"number"==typeof t?t:s(...t,e?"round":void 0)}const l=(t=.5)=>Math.random()<t,a=t=>({value:t}),c=t=>[...t].map(a),g="(&#?[0-9a-zA-Z]{2,6};)|(<style.+?>.+?</style>|<script.+?>.+?<\/script>|<(?:!|/?[a-zA-Z]+).*?/?>)";function u(t){const e=new RegExp(g,"g");return t.replace(e,"")}const p={nier:"一二三四五六七八九十百千上下左右中大小月日年早木林山川土空田天生花草虫犬人名女男子目耳口手足見音力気円入出立休先夕本文字学校村町森正水火玉王石竹糸貝車金雨赤青白数多少万半形太細広長点丸交光角計直線矢弱強高同親母父姉兄弟妹自友体毛頭顔首心時曜朝昼夜分週春夏秋冬今新古間方北南東西遠近前後内外場地国園谷野原里市京風雪雲池海岩星室戸家寺通門道話言答声聞語読書記紙画絵図工教晴思考知才理算作元食肉馬牛魚鳥羽鳴麦米茶色黄黒来行帰歩走止活店買売午汽弓回会組船明社切電毎合当台楽公引科歌刀番用何",full:"ABCDĐEFGHIJKLMNOPQRSTUVWXYZabcdđefghijklmnopqrstuvwxyzĄąĆ毿ŹźŃńóŁłАБВГҐДЂЕЁЄЖЗЅИІЇЙЈКЛЉМНЊОПРСТЋУЎФХЦЧЏШЩЪЫЬЭЮЯабвгґдђеёєжзѕиіїйјклљмнњопрстћуўфхцчџшщъыьэюяΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψωάΆέΈέΉίϊΐΊόΌύΰϋΎΫΏĂÂÊÔƠƯăâêôơư一二三四五六七八九十百千上下左右中大小月日年早木林山川土空田天生花草虫犬人名女男子目耳口手足見音力気円入出立休先夕本文字学校村町森正水火玉王石竹糸貝車金雨赤青白数多少万半形太細広長点丸交光角計直線矢弱強高同親母父姉兄弟妹自友体毛頭顔首心時曜朝昼夜分週春夏秋冬今新古間方北南東西遠近前後内外場地国園谷野原里市京風雪雲池海岩星室戸家寺通門道話言答声聞語読書記紙画絵図工教晴思考知才理算作元食肉馬牛魚鳥羽鳴麦米茶色黄黒来行帰歩走止活店買売午汽弓回会組船明社切電毎合当台楽公引科歌刀番用何ĂÂÊÔƠƯăâêôơư1234567890‘?’“!”(%)[#]{@}/\\&<-+÷×=>$€£¥¢:;,.*•°·…±†‡æ«»¦¯—–~˜¨_øÞ¿▬▭▮▯┐└╛░▒▓○‼⁇⁈⁉‽ℴℵℶℷℸℲ℮ℯ⅁⅂⅃⅄₠₡₢₣₤₥₦₧₨₩₪₫€₭₮₯₰₱₲₳₴₵₶₷₸₹₺₻₼₽₾₿ ",letterlike:"ABCDĐEFGHIJKLMNOPQRSTUVWXYZabcdđefghijklmnopqrstuvwxyzĄąĆ毿ŹźŃńóŁłАБВГҐДЂЕЁЄЖЗЅИІЇЙЈКЛЉМНЊОПРСТЋУЎФХЦЧЏШЩЪЫЬЭЮЯабвгґдђеёєжзѕиіїйјклљмнњопрстћуўфхцчџшщъыьэюяΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψωάΆέΈέΉίϊΐΊόΌύΰϋΎΫΏĂÂÊÔƠƯăâêôơưĂÂÊÔƠƯăâêôơư1234567890",zalgo:"̴̵̶̷̸̡̢̧̨̛̖̗̘̙̜̝̞̟̠̣̤̥̦̩̪̫̬̭̮̯̰̱̲̳̹̺̻̼͇͈͉͍͎̀́̂̃̄̅̆̇̈̉̊̋̌̍̎̏̐̑̒̓̔̽̾̿̀́͂̓̈́͆͊͋͌̕̚ͅ ͓͔͕͖͙͚͐͑͒͗͛ͣͤͥͦͧͨͩͪͫͬͭͮͯ͘͜͟͢͝͞͠͡͏҉",neo:"!<>-_\\/[]{}—=+*^?#________",uppercase:"1234567890QWERTYUIOPASDFGHJKLZXCVBNM#$%"},d={default:{steps:[1,8],interval:[60,170],initialDelay:[0,2e3],changeChance:.6,ghostChance:.2,maxGhosts:.2,glyphs:p.full+p.zalgo,glyphsFromString:!1,oneAtATime:!1,html:!1,fillSpace:!0,letterize:!1,endless:!1,startFrom:"matching"},nier:{maxGhosts:0,ghostChance:0,changeChance:.8,steps:2,interval:10,initialDelay:0,glyphs:p.nier,oneAtATime:!0,startFrom:"erase",glyphsFromString:!0},typewriter:{interval:[40,100],initialDelay:[0,0],steps:[0,1],changeChance:1,maxGhosts:0,glyphs:"",glyphsFromString:!0,oneAtATime:!0,startFrom:"erase"},terminal:{interval:[25,30],initialDelay:[0,0],steps:0,changeChance:.5,maxGhosts:0,glyphs:"",oneAtATime:!0,fillSpace:!1,glyphsFromString:!1,startFrom:"erase"},zalgo:{initialDelay:[0,3e3],interval:[10,35],steps:[0,30],maxGhosts:4.6,changeChance:.5,ghostChance:.7,glyphs:p.zalgo,glyphsFromString:!0,fillSpace:!1},neo:{glyphs:p.neo,maxGhosts:0,ghostChance:0,changeChance:1,interval:[30,100],initialDelay:[0,1300],steps:[4,7],startFrom:"previous",letterize:!0},encrypted:{glyphs:p.uppercase,maxGhosts:0,ghostChance:0,changeChance:1,interval:[50,90],initialDelay:[0,1300],steps:[5,8],startFrom:"previous",fillSpace:!1,letterize:!0}};class f{constructor(t,e){var s,i,n,r,h,o,l,a,c,g,u,p,f,m;"string"==typeof e&&(e=d[e]),e||(e={}),this.steps=null!==(s=e.steps)&&void 0!==s?s:d.default.steps,this.interval=null!==(i=e.interval)&&void 0!==i?i:d.default.interval,this.initialDelay=null!==(n=e.initialDelay)&&void 0!==n?n:d.default.initialDelay,this.changeChance=null!==(r=e.changeChance)&&void 0!==r?r:d.default.changeChance,this.ghostChance=null!==(h=e.ghostChance)&&void 0!==h?h:d.default.ghostChance,this.maxGhosts=null!==(o=e.maxGhosts)&&void 0!==o?o:d.default.maxGhosts,this.glyphs=null!==(l=function(t){if(void 0===t)return;let e;return e="string"==typeof t?t:t.length?t.join(""):Array.from(t).join(""),e}(e.glyphs))&&void 0!==l?l:d.default.glyphs,this.glyphsFromString=null!==(a=e.glyphsFromString)&&void 0!==a?a:d.default.glyphsFromString,this.ghostCharset=[...this.glyphs],this.oneAtATime=null!==(c=e.oneAtATime)&&void 0!==c?c:d.default.oneAtATime,this.html=null!==(g=e.html)&&void 0!==g?g:d.default.html,this.letterize=null!==(u=e.letterize)&&void 0!==u?u:d.default.letterize,this.endless=null!==(p=e.endless)&&void 0!==p?p:d.default.endless,"undefined"==typeof document&&(this.letterize=!1),this.startFrom=null!==(f=e.startFrom)&&void 0!==f?f:d.default.startFrom,this.writer=t,this.space=(null!==(m=e.fillSpace)&&void 0!==m?m:d.default.fillSpace)?" ":""}get stepsLeft(){return o(this.steps)}get genInterval(){return o(this.interval)}get genInitDelay(){return o(this.initialDelay)}get genMaxGhosts(){if(Number.isInteger(this.maxGhosts))return this.maxGhosts;let t;return t=this.writer.options.html?u(this.writer.goalString).length:this.writer.goalString.length,Math.round((t||20)*this.maxGhosts)}get genGhost(){var t,e;return null!==(t=(e=this.ghostCharset)[s(0,e.length,"floor")])&&void 0!==t?t:""}setCharset(){let t=this.glyphs;this.glyphsFromString&&(t+=function(t){const e="string"==typeof t,s=[];return new Set(t).forEach((t=>s.push(t))),e?s.join(""):s}(this.writer.previousString+(this.writer.options.html?u(this.writer.goalString):this.writer.goalString))),this.ghostCharset=[...t].filter((t=>!["\t","\n","\r","\f","\v"].includes(t)))}}class m{constructor(t){this.nGhosts=0,this.isTyping=!1,this.isPaused=!1,this.finished=!1,this.writer=t,this.maxGhosts=this.writer.options.genMaxGhosts}get ghostsInLimit(){return this.nGhosts<this.maxGhosts}play(){this.isTyping=!0,this.isPaused=!1,this.finished=!1,this.toggleClass(!0),this.maxGhosts=this.writer.options.genMaxGhosts}pause(){this.isTyping=!1,this.isPaused=!0,this.toggleClass(!1)}finish(){this.isTyping=!1,this.finished=!0,this.toggleClass(!1)}toggleClass(t){const e=this.writer.htmlElement,s="gw-writing";e&&(t?((t,e)=>{t.classList.remove(e),t.offsetWidth,t.classList.add(e)})(e,s):e.classList.remove(s))}}var v=function(t,e,s,i){return new(s||(s=Promise))((function(n,r){function h(t){try{l(i.next(t))}catch(t){r(t)}}function o(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(h,o)}l((i=i.apply(t,e||[])).next())}))};class y{constructor(t,e,s,i="",n=!1){this.ghostsBefore=[],this.ghostsAfter=[],this.stop=!1,this.isTag=!1,this.isWhitespace=!1,this.afterGlitchChance=0,this.writer=t,this.setProps(e,s,i,n),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")}setProps(t,e,s="",i=!1){const{options:n}=this.writer;this.l=t,this.gl=e,this.isTag=i,this.ghostsBefore=[...s],this.writer.state.nGhosts+=s.length,this.stepsLeft=n.stepsLeft,i&&(this.stepsLeft=0),this.isWhitespace=(t=>["\t","\n","\r","\f","\v",""," "].includes(t))(e),this.afterGlitchChance=(n.ghostChance+n.changeChance)/3.7}reset(t,e,s="",i=!1){this.setProps(t,e,s,i),this.els&&(this.els.letterEl.className="gw-letter")}get string(){const{l:t,ghostsAfter:e,ghostsBefore:s}=this;return s.join("")+t+e.join("")}get finished(){const{l:t,gl:e,ghostsBefore:s,ghostsAfter:i}=this;return t===e&&0===s.length&&0===i.length||this.isTag}get interval(){let t=this.writer.options.genInterval;return this.isWhitespace&&(t/=2),t}writeToElement(){if(!this.els)return;const{ghostsBeforeEl:t,ghostsAfterEl:e,letterEl:s}=this.els;s.innerHTML=this.l,t.textContent=this.ghostsBefore.join(""),e.textContent=this.ghostsAfter.join("")}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,s;return v(this,void 0,void 0,(function*(){const{writer:i}=this;return this.isTag?(this.l=this.gl,i.emiter.call("step"),!0):(yield n(i.options.genInitDelay),yield r((()=>(!this.finished||i.options.endless)&&!i.state.isPaused&&!this.stop),(()=>v(this,void 0,void 0,(function*(){yield n(this.interval);const t=this.string;this.step(),t!==this.string&&(i.emiter.call("step"),this.writeToElement()),!i.options.endless&&this.stepsLeft--})))),this.finished&&(null===(e=null===(t=this.els)||void 0===t?void 0:t.charEl)||void 0===e||e.classList.add("gw-finished"),null===(s=this.els)||void 0===s||s.letterEl.classList.remove("gw-glitched")),this.finished)}))}step(){var t,e;const{writer:s}=this;if(this.stepsLeft>0&&this.l!==this.gl||l(this.afterGlitchChance)&&!this.isWhitespace||s.options.endless){const{ghostChance:e,changeChance:i}=s.options;l(e)&&(s.state.ghostsInLimit?this.addGhost():this.removeGhost()),l(i)&&(null===(t=this.els)||void 0===t||t.letterEl.classList.add("gw-glitched"),this.l=s.options.genGhost)}else this.finished||(null===(e=this.els)||void 0===e||e.letterEl.classList.remove("gw-glitched"),this.l=this.gl,this.removeGhost())}addGhost(){const t=this.writer.options.genGhost;this.writer.state.nGhosts++,l()?w(this.ghostsBefore,t):w(this.ghostsAfter,t)}removeGhost(){(l()&&this.ghostsBefore.length>0?i(this.ghostsBefore):i(this.ghostsAfter))&&this.writer.state.nGhosts--}}function w(t,e){const{length:i}=t;t.splice(s(0,i,"floor"),0,e)}var C=function(t,e,s,i){return new(s||(s=Promise))((function(n,r){function h(t){try{l(i.next(t))}catch(t){r(t)}}function o(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(h,o)}l((i=i.apply(t,e||[])).next())}))};class E{constructor(t,e,s,i){var n;this.charTable=[],this.goalString="",this.string="","string"==typeof t?"undefined"!=typeof document&&(this.htmlElement=null!==(n=document.querySelector(t))&&void 0!==n?n:void 0):this.htmlElement=null!=t?t:void 0,this.options=new f(this,e),this.state=new m(this),this.emiter=new class{constructor(t,e,s){this.onStepCallback=e,this.onFinishCallback=s,this.writer=t}call(t){var e,s;this.writer.updateString();const{htmlElement:i,writerData:n,string:r}=this.writer;i&&!this.writer.options.letterize&&(this.writer.options.html?i.innerHTML=r:i.textContent=r),null==i||i.setAttribute("data-gw-string",this.writer.options.html?u(r):r),"finish"===t?(this.writer.state.finish(),null===(e=this.onFinishCallback)||void 0===e||e.call(this,r,n),this.emitEvent()):null===(s=this.onStepCallback)||void 0===s||s.call(this,r,n)}emitEvent(){const{htmlElement:t,writerData:e}=this.writer;t&&"undefined"!=typeof CustomEvent&&(null==t||t.dispatchEvent(new CustomEvent("gw-finished",{detail:e})))}}(this,s,i),this.string=this.previousString}updateString(){this.string=this.charTable.map((t=>t.string)).join("")}get previousString(){var t;let e=null===(t=this.htmlElement)||void 0===t?void 0:t.textContent;return"string"!=typeof e&&(e=this.options.html?u(this.string):this.string),e=e.trim(),e}get writerData(){const{options:t,state:e,string:s}=this;return{string:s,writer:this,options:t,state:e}}write(t,e){return C(this,void 0,void 0,(function*(){return"erase"!==this.options.startFrom||(null==e?void 0:e.erase)||(yield this.write(this.genGoalStringToErase(t),{erase:!0})),this.goalString=t,this.state.nGhosts=0,this.options.setCharset(),"matching"===this.options.startFrom?this.createMatchingCharTable():this.createPreviousCharTable(),this.letterize(),this.pause(),this.play({reverse:this.options.oneAtATime&&(null==e?void 0:e.erase)})}))}add(t){return C(this,void 0,void 0,(function*(){const{previousString:e}=this;return this.write(e+t)}))}remove(t){return C(this,void 0,void 0,(function*(){const{previousString:e}=this,s=Array.from(e);return s.splice(-t),this.write(s.join(""),{erase:!0})}))}play(t){var e;return C(this,void 0,void 0,(function*(){const s=[],{charTable:i}=this,{length:n}=i;if(this.state.isTyping)return this.getWriterData("ERROR",`The writer is already typing "${this.goalString}".`);if(this.state.play(),this.options.oneAtATime){const s=null!==(e=null==t?void 0:t.reverse)&&void 0!==e&&e;let h=s?n-1:0,o=!0;const l=()=>C(this,void 0,void 0,(function*(){o=yield i[h].type(),s?h--:h++}));return yield r((()=>{return(t=h)>=0&&t<n&&o&&!this.state.isPaused;var t}),l),this.returnResult(o)}i.forEach((t=>s.push(t.type())));try{const t=(yield Promise.all(s)).every((t=>t));return this.returnResult(t)}catch(t){return this.getWriterData("ERROR","Writer encountered an error.",t)}}))}pause(){this.state.pause()}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.")}createMatchingCharTable(){const{goalStringArray:t,previousString:e}=this,s=Math.min(Math.ceil(this.options.genMaxGhosts/2),5);let i=-1;t.forEach(((t,n)=>{if(i++,"tag"===t.type)return i--,void this.setChar(n,"",t);const r=""!==t.value?e.indexOf(t.value,i):-1;if(-1!==r&&r-i<=s){const s=e.substring(i,r);this.setChar(n,t.value,t,s),i=r}else this.setChar(n,e[i],t)})),this.removeExtraChars(t.length)}createPreviousCharTable(){const{goalStringArray:t,previousString:e}=this;let s=-1;t.forEach(((t,i)=>{if(s++,"tag"===t.type)return s--,void this.setChar(i,"",t);this.setChar(i,e[s],t)})),this.removeExtraChars(t.length)}letterize(){if(!this.options.letterize||!this.htmlElement)return;const t=this.charTable.map((({isTag:t,gl:e})=>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=>{t.isTag||(t.spanElement=e[s],s++)}))}removeExtraChars(t){const{charTable:e}=this;e.splice(t,e.length-t)}setChar(t,e,s,i){const{charTable:n}=this,r=n[t];r?r.reset(null!=e?e:"",s.value||this.options.space,i,"tag"===s.type):n.push(new y(this,null!=e?e:"",s.value||this.options.space,i,"tag"===s.type))}get goalStringArray(){const{goalString:t,options:e,previousString:s}=this,i=e.html?function(t){const e=new RegExp(g,"g"),s=[];let i,n=0;for(;i=e.exec(t);){const r=i.index,h=e.lastIndex,o=t.slice(n,r);n=h,o&&s.push(...c(o));const l={value:i[0],type:void 0!==i[1]?"html_entity":"tag"};s.push(l)}return t.length>n&&s.push(...c(t.slice(n))),s}(t):c(t),n=Math.max(0,s.length-i.length);if(this.options.oneAtATime)return i.concat(c(h("",n)));const r=Math.ceil(n/2),o=Math.floor(n/2);return c(h("",r)).concat(i,c(h("",o)))}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="";for(let n=0;n<t.length;n++){const r=t[n],h=null!==(e=s[n])&&void 0!==e?e:"";if(r!==h)break;i+=h}const n=Math.max(t.length-i.length,0);return n>0&&" "===this.options.space&&(i=i.padEnd(n+i.length," ")),i}}function S(t,e,s,i,n){return C(this,void 0,void 0,(function*(){return new E(e,s,i,n).write(t)}))}return e})()})); | ||
//# sourceMappingURL=index.min.map |
{ | ||
"name": "glitched-writer", | ||
"version": "2.0.18", | ||
"version": "2.0.19", | ||
"description": "Glitched, text writing module. Highly customizable settings. Decoding, decrypting, scrambling, and simply spelling text.", | ||
@@ -5,0 +5,0 @@ "author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>", |
@@ -49,2 +49,3 @@ # Glitched Writer | ||
- [Letterize](#letterize) | ||
- [Endless option](#endless-animation) | ||
- [Available imports](#available-imports) | ||
@@ -77,3 +78,3 @@ 3. **[Presets](#presets)** | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/glitched-writer@2.0.14/lib/index.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/glitched-writer@2.0.18/lib/index.min.js"></script> | ||
``` | ||
@@ -235,3 +236,3 @@ | ||
passEl.addEventListener('mouseover', () => { | ||
Writer.options.endless = true | ||
Writer.options.endless = false | ||
}) | ||
@@ -320,3 +321,3 @@ | ||
letterize?: boolean, // false | ||
fillSpace?: boolean // true | ||
fillSpace?: boolean, // true | ||
endless?: boolean // false | ||
@@ -323,0 +324,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
240785
2250
373