glitched-writer
Advanced tools
Comparing version 1.0.4 to 1.1.0
@@ -53,2 +53,4 @@ { | ||
"function-paren-newline":"off", | ||
"no-await-in-loop": "warn", | ||
"no-mixed-spaces-and-tabs":"warn", | ||
"indent": [ | ||
@@ -55,0 +57,0 @@ "off", |
@@ -25,2 +25,4 @@ const random = (min, max, mathFunc = null) => { | ||
glitchesFromString: false, | ||
oneAtATime: false, | ||
clearStart: false, | ||
} | ||
@@ -103,2 +105,10 @@ | ||
if (settings.clearStart) { | ||
this.textTable = this.textTable.map(char => ({ | ||
...char, | ||
l: '', | ||
})) | ||
el.textContent = '' | ||
} | ||
const { textTable } = this | ||
@@ -123,9 +133,13 @@ | ||
glitches ? glitches[random(0, glitches.length, 'floor')] : l || '', | ||
lastMatching = after.reduce((last, l, i) => { | ||
if (i >= textTable.length) return last | ||
return last === i - 1 && | ||
l.toLowerCase() === textTable[i].l.toLowerCase() | ||
? i | ||
: last | ||
}, -1) | ||
lastMatching = settings.oneAtATime | ||
? textTable.length - 1 | ||
: after.reduce( | ||
(last, l, i) => | ||
i < textTable.length && | ||
last === i - 1 && | ||
l.toLowerCase() === textTable[i].l.toLowerCase() | ||
? i | ||
: last, | ||
-1, | ||
) | ||
@@ -145,5 +159,14 @@ while (textTable.length < after.length) | ||
const promiseList = after.map((l, i) => handleLetter(i, l)) | ||
let results = [] | ||
const results = await Promise.all(promiseList) | ||
if (settings.oneAtATime) { | ||
// eslint-disable-next-line | ||
for (let i in after) { | ||
const promise = await handleLetter(i, after[i]) | ||
results.push(promise) | ||
} | ||
} else { | ||
const promiseList = after.map((l, i) => handleLetter(i, l)) | ||
results = await Promise.all(promiseList) | ||
} | ||
@@ -150,0 +173,0 @@ let result = results.every(r => r) |
@@ -27,2 +27,4 @@ const regeneratorRuntime = require('regenerator-runtime') | ||
glitchesFromString: false, | ||
oneAtATime: false, | ||
clearStart: false, | ||
} | ||
@@ -105,2 +107,10 @@ | ||
if (settings.clearStart) { | ||
this.textTable = this.textTable.map(char => ({ | ||
...char, | ||
l: '', | ||
})) | ||
el.textContent = '' | ||
} | ||
const { textTable } = this | ||
@@ -125,9 +135,12 @@ | ||
glitches ? glitches[random(0, glitches.length, 'floor')] : l || '', | ||
lastMatching = after.reduce((last, l, i) => { | ||
if (i >= textTable.length) return last | ||
return last === i - 1 && | ||
l.toLowerCase() === textTable[i].l.toLowerCase() | ||
? i | ||
: last | ||
}, -1) | ||
lastMatching = settings.oneAtATime | ||
? textTable.length - 1 | ||
: after.reduce( | ||
(last, l, i) => | ||
i < textTable.length && last === i - 1 && | ||
l.toLowerCase() === textTable[i].l.toLowerCase() | ||
? i | ||
: last, | ||
-1, | ||
) | ||
@@ -147,5 +160,14 @@ while (textTable.length < after.length) | ||
const promiseList = after.map((l, i) => handleLetter(i, l)) | ||
let results = [] | ||
const results = await Promise.all(promiseList) | ||
if (settings.oneAtATime) { | ||
// eslint-disable-next-line | ||
for (let i in after) { | ||
const promise = await handleLetter(i, after[i]) | ||
results.push(promise) | ||
} | ||
} else { | ||
const promiseList = after.map((l, i) => handleLetter(i, l)) | ||
results = await Promise.all(promiseList) | ||
} | ||
@@ -152,0 +174,0 @@ let result = results.every(r => r) |
parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"KA2S":[function(require,module,exports) { | ||
var t=function(t){"use strict";var r,e=Object.prototype,n=e.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,r,e,n){var o=r&&r.prototype instanceof v?r:v,i=Object.create(o.prototype),a=new k(n||[]);return i._invoke=function(t,r,e){var n=f;return function(o,i){if(n===l)throw new Error("Generator is already running");if(n===p){if("throw"===o)throw i;return N()}for(e.method=o,e.arg=i;;){var a=e.delegate;if(a){var c=_(a,e);if(c){if(c===y)continue;return c}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if(n===f)throw n=p,e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n=l;var u=h(t,r,e);if("normal"===u.type){if(n=e.done?p:s,u.arg===y)continue;return{value:u.arg,done:e.done}}"throw"===u.type&&(n=p,e.method="throw",e.arg=u.arg)}}}(t,e,a),i}function h(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(n){return{type:"throw",arg:n}}}t.wrap=u;var f="suspendedStart",s="suspendedYield",l="executing",p="completed",y={};function v(){}function d(){}function g(){}var m={};m[i]=function(){return this};var w=Object.getPrototypeOf,L=w&&w(w(G([])));L&&L!==e&&n.call(L,i)&&(m=L);var x=g.prototype=v.prototype=Object.create(m);function E(t){["next","throw","return"].forEach(function(r){t[r]=function(t){return this._invoke(r,t)}})}function b(t){var r;this._invoke=function(e,o){function i(){return new Promise(function(r,i){!function r(e,o,i,a){var c=h(t[e],t,o);if("throw"!==c.type){var u=c.arg,f=u.value;return f&&"object"==typeof f&&n.call(f,"__await")?Promise.resolve(f.__await).then(function(t){r("next",t,i,a)},function(t){r("throw",t,i,a)}):Promise.resolve(f).then(function(t){u.value=t,i(u)},function(t){return r("throw",t,i,a)})}a(c.arg)}(e,o,r,i)})}return r=r?r.then(i,i):i()}}function _(t,e){var n=t.iterator[e.method];if(n===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=r,_(t,e),"throw"===e.method))return y;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return y}var o=h(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,y;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=r),e.delegate=null,y):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,y)}function j(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function O(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function k(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(j,this),this.reset(!0)}function G(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,a=function e(){for(;++o<t.length;)if(n.call(t,o))return e.value=t[o],e.done=!1,e;return e.value=r,e.done=!0,e};return a.next=a}}return{next:N}}function N(){return{value:r,done:!0}}return d.prototype=x.constructor=g,g.constructor=d,g[c]=d.displayName="GeneratorFunction",t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===d||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,c in t||(t[c]="GeneratorFunction")),t.prototype=Object.create(x),t},t.awrap=function(t){return{__await:t}},E(b.prototype),b.prototype[a]=function(){return this},t.AsyncIterator=b,t.async=function(r,e,n,o){var i=new b(u(r,e,n,o));return t.isGeneratorFunction(e)?i:i.next().then(function(t){return t.done?t.value:i.next()})},E(x),x[c]="Generator",x[i]=function(){return this},x.toString=function(){return"[object Generator]"},t.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=G,k.prototype={constructor:k,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=r,this.done=!1,this.delegate=null,this.method="next",this.arg=r,this.tryEntries.forEach(O),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=r)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function o(n,o){return c.type="throw",c.arg=t,e.next=n,o&&(e.method="next",e.arg=r),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),h=n.call(a,"finallyLoc");if(u&&h){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!h)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var o=this.tryEntries[e];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),y},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),O(e),y}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;O(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:G(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=r),y}},t}("object"==typeof module?module.exports:{});try{regeneratorRuntime=t}catch(r){Function("r","regeneratorRuntime = r")(t)} | ||
},{}],"HLE4":[function(require,module,exports) { | ||
function t(t,e,n,r,i,s,o){try{var a=t[s](o),u=a.value}catch(c){return void n(c)}a.done?e(u):Promise.resolve(u).then(r,i)}function e(e){return function(){var n=this,r=arguments;return new Promise(function(i,s){var o=e.apply(n,r);function a(e){t(o,i,s,a,u,"next",e)}function u(e){t(o,i,s,a,u,"throw",e)}a(void 0)})}}function n(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)}return n}function r(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?n(r,!0).forEach(function(e){a(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):n(r).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function s(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function o(t,e,n){return e&&s(t.prototype,e),n&&s(t,n),t}function a(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function u(t){return h(t)||l(t)||c()}function c(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function l(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}function h(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}var f=require("regenerator-runtime"),p=function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=Math.random()*(e-t)+t;return null==n?r:Math[n](r)},g=function(t){return u(new Set(u(t))).reduce(function(t,e){return t+e})},y=function(){function t(e,n){var s=this;i(this,t),a(this,"prevWrongSettings",function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:s.settings;t.stepsMax=Math.max(t.stepsMax,t.stepsMin),t.delayMax=Math.max(t.delayMax,t.delayMin)}),this.state=t.state,this.settings=r({},t.settings,{},n),this.prevWrongSettings(),this.el=e,this.text="",this.endEvent=new CustomEvent("glitchWrote",{detail:this})}return o(t,[{key:"write",value:function(t,e){return this.text=t,this.state.typing?(this.stop(!0),Promise.resolve({finished:!1,restarting:this.state.restart,element:this.el,text:this.text,description:"".concat(this.el.outerHTML,' is typing: "').concat(this.text,'"'),textTable:this.textTable})):(this.state.stop=!1,e=r({},this.settings,{},e),this.prevWrongSettings(e),this.accualWrite(e))}},{key:"stop",value:function(t){if(this.state.restart=Boolean(t),this.state.stop)return!1;this.state.stop=!0}},{key:"accualWrite",value:function(){var t=e(f.mark(function t(e){var n,i,s,o,a,c,l,h,y,v,d,b,x,m,w,M,O,P,j,T,S,E;return f.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:for(E=function(t,e){return new Promise(function(n){var r=x[t];!function t(){if(s.stop)return void n(!1);setTimeout(function(){if(r.steps--,r.l=r.steps<=0||r.l===e?e:M(r.l),r.l===e&&""!==r.ghosts?r.ghosts=r.ghosts.slice(0,-1):b>0&&Math.random()<y&&(r.ghosts+=M(),b--),w(),r.l===e&&""===r.ghosts)return r.steps=0,void n(!0);t()},p(l,h))}()})},n=this.text,i=this.el,s=this.state,o=u(n)||[" "],a=e.stepsMin,c=e.stepsMax,l=e.delayMin,h=e.delayMax,y=e.ghostsProbability,v=function(){return p(a,c,"floor")},d=e.glitchesFromString?g(n+i.textContent):e.glitches,b=e.maxGhosts,this.textTable=(this.textTable||u(i.textContent).filter(function(t){return"\n"!==t}).map(function(t){return{l:t,ghosts:""}})).map(function(t){return r({},t,{steps:v()})}),x=this.textTable,s.typing=!0,i.classList.add("glitch-writing"),x.forEach(function(t,e){return x[e].steps=v()}),m=function(){return x.reduce(function(t,e){return t+(e.l+e.ghosts)},"")},w=function(){var t=m();i.textContent=t,i.setAttribute("data-decrypted-text",t)},M=function(t){return d?d[p(0,d.length,"floor")]:t||""},O=o.reduce(function(t,e,n){return n>=x.length?t:t===n-1&&e.toLowerCase()===x[n].l.toLowerCase()?n:t},-1);x.length<o.length;)x.splice(p(O+1,x.length,"floor"),0,{l:"",steps:v(),ghosts:""});for(;x.length>o.length;)o.splice(p(O+1,o.length,"floor"),0,"");return P=o.map(function(t,e){return E(e,t)}),t.next=14,Promise.all(P);case 14:return j=t.sent,T=j.every(function(t){return t}),S=s.restart,s.restart=!1,s.typing=!1,i.classList.remove("glitch-writing"),(T={finished:T,restarting:S,element:this.el,text:n,description:"".concat(this.el.outerHTML,' types: "').concat(n,'"'),textTable:this.textTable}).finished&&i.dispatchEvent(this.endEvent),t.abrupt("return",!T.finished&&S||this.text!==m()?this.write(this.text,d,e):T);case 23:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()}]),t}();a(y,"state",{stop:!1,typing:!1,restart:!1}),a(y,"settings",{stepsMin:0,stepsMax:6,delayMin:140,delayMax:400,ghostsProbability:.1,maxGhosts:7,glitches:"ABCDĐEFGHIJKLMNOPQRSTUVWXYZabcdđefghijklmnopqrstuvwxyzĄąĆ毿ŹźŃńóŁłАБВГҐДЂЕЁЄЖЗЅИІЇЙЈКЛЉМНЊОПРСТЋУЎФХЦЧЏШЩЪЫЬЭЮЯабвгґдђеёєжзѕиіїйјклљмнњопрстћуўфхцчџшщъыьэюяΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψωάΆέΈέΉίϊΐΊόΌύΰϋΎΫΏĂÂÊÔƠƯăâêôơư一二三四五六七八九十百千上下左右中大小月日年早木林山川土空田天生花草虫犬人名女男子目耳口手足見音力気円入出立休先夕本文字学校村町森正水火玉王石竹糸貝車金雨赤青白数多少万半形太細広長点丸交光角計直線矢弱強高同親母父姉兄弟妹自友体毛頭顔首心時曜朝昼夜分週春夏秋冬今新古間方北南東西遠近前後内外場地国園谷野原里市京風雪雲池海岩星室戸家寺通門道話言答声聞語読書記紙画絵図工教晴思考知才理算作元食肉馬牛魚鳥羽鳴麦米茶色黄黒来行帰歩走止活店買売午汽弓回会組船明社切電毎合当台楽公引科歌刀番用何ĂÂÊÔƠƯăâêôơư1234567890‘?’“!”(%)[#]{@}/&<-+÷×=>$€£¥¢:;,.* •°·…±†‡æ«»¦¯—–~˜¨_øÞ¿▬▭▮▯┐└╛╟╚╔╘╒╓┘┌░▒▓○‼",glitchesFromString:!1});var v=function(t,e,n){return new y(t,n).write(e)},d=function(t,e){return new y(t,e)};module.exports={setGlitchedWriter:d,glitchWrite:v}; | ||
function t(t,e,n,r,i,s,o){try{var a=t[s](o),c=a.value}catch(u){return void n(u)}a.done?e(c):Promise.resolve(c).then(r,i)}function e(e){return function(){var n=this,r=arguments;return new Promise(function(i,s){var o=e.apply(n,r);function a(e){t(o,i,s,a,c,"next",e)}function c(e){t(o,i,s,a,c,"throw",e)}a(void 0)})}}function n(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)}return n}function r(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?n(r,!0).forEach(function(e){a(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):n(r).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function s(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function o(t,e,n){return e&&s(t.prototype,e),n&&s(t,n),t}function a(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function c(t){return h(t)||l(t)||u()}function u(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function l(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}function h(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}var f=require("regenerator-runtime"),p=function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=Math.random()*(e-t)+t;return null==n?r:Math[n](r)},g=function(t){return c(new Set(c(t))).reduce(function(t,e){return t+e})},y=function(){function t(e,n){var s=this;i(this,t),a(this,"prevWrongSettings",function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:s.settings;t.stepsMax=Math.max(t.stepsMax,t.stepsMin),t.delayMax=Math.max(t.delayMax,t.delayMin)}),this.state=t.state,this.settings=r({},t.settings,{},n),this.prevWrongSettings(),this.el=e,this.text="",this.endEvent=new CustomEvent("glitchWrote",{detail:this})}return o(t,[{key:"write",value:function(t,e){return this.text=t,this.state.typing?(this.stop(!0),Promise.resolve({finished:!1,restarting:this.state.restart,element:this.el,text:this.text,description:"".concat(this.el.outerHTML,' is typing: "').concat(this.text,'"'),textTable:this.textTable})):(this.state.stop=!1,e=r({},this.settings,{},e),this.prevWrongSettings(e),this.accualWrite(e))}},{key:"stop",value:function(t){if(this.state.restart=Boolean(t),this.state.stop)return!1;this.state.stop=!0}},{key:"accualWrite",value:function(){var t=e(f.mark(function t(e){var n,i,s,o,a,u,l,h,y,b,v,d,x,m,w,M,O,P,T,j,A,S,k,E;return f.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:for(E=function(t,e){return new Promise(function(n){var r=x[t];!function t(){if(s.stop)return void n(!1);setTimeout(function(){if(r.steps--,r.l=r.steps<=0||r.l===e?e:M(r.l),r.l===e&&""!==r.ghosts?r.ghosts=r.ghosts.slice(0,-1):d>0&&Math.random()<y&&(r.ghosts+=M(),d--),w(),r.l===e&&""===r.ghosts)return r.steps=0,void n(!0);t()},p(l,h))}()})},n=this.text,i=this.el,s=this.state,o=c(n)||[" "],a=e.stepsMin,u=e.stepsMax,l=e.delayMin,h=e.delayMax,y=e.ghostsProbability,b=function(){return p(a,u,"floor")},v=e.glitchesFromString?g(n+i.textContent):e.glitches,d=e.maxGhosts,this.textTable=(this.textTable||c(i.textContent).filter(function(t){return"\n"!==t}).map(function(t){return{l:t,ghosts:""}})).map(function(t){return r({},t,{steps:b()})}),e.clearStart&&(this.textTable=this.textTable.map(function(t){return r({},t,{l:""})}),i.textContent=""),x=this.textTable,s.typing=!0,i.classList.add("glitch-writing"),x.forEach(function(t,e){return x[e].steps=b()}),m=function(){return x.reduce(function(t,e){return t+(e.l+e.ghosts)},"")},w=function(){var t=m();i.textContent=t,i.setAttribute("data-decrypted-text",t)},M=function(t){return v?v[p(0,v.length,"floor")]:t||""},O=e.oneAtATime?x.length-1:o.reduce(function(t,e,n){return n<x.length&&t===n-1&&e.toLowerCase()===x[n].l.toLowerCase()?n:t},-1);x.length<o.length;)x.splice(p(O+1,x.length,"floor"),0,{l:"",steps:b(),ghosts:""});for(;x.length>o.length;)o.splice(p(O+1,o.length,"floor"),0,"");if(P=[],!e.oneAtATime){t.next=25;break}t.t0=f.keys(o);case 15:if((t.t1=t.t0()).done){t.next=23;break}return T=t.t1.value,t.next=19,E(T,o[T]);case 19:j=t.sent,P.push(j),t.next=15;break;case 23:t.next=29;break;case 25:return A=o.map(function(t,e){return E(e,t)}),t.next=28,Promise.all(A);case 28:P=t.sent;case 29:return S=P.every(function(t){return t}),k=s.restart,s.restart=!1,s.typing=!1,i.classList.remove("glitch-writing"),(S={finished:S,restarting:k,element:this.el,text:n,description:"".concat(this.el.outerHTML,' types: "').concat(n,'"'),textTable:this.textTable}).finished&&i.dispatchEvent(this.endEvent),t.abrupt("return",!S.finished&&k||this.text!==m()?this.write(this.text,v,e):S);case 37:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()}]),t}();a(y,"state",{stop:!1,typing:!1,restart:!1}),a(y,"settings",{stepsMin:0,stepsMax:6,delayMin:140,delayMax:400,ghostsProbability:.1,maxGhosts:7,glitches:"ABCDĐEFGHIJKLMNOPQRSTUVWXYZabcdđefghijklmnopqrstuvwxyzĄąĆ毿ŹźŃńóŁłАБВГҐДЂЕЁЄЖЗЅИІЇЙЈКЛЉМНЊОПРСТЋУЎФХЦЧЏШЩЪЫЬЭЮЯабвгґдђеёєжзѕиіїйјклљмнњопрстћуўфхцчџшщъыьэюяΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψωάΆέΈέΉίϊΐΊόΌύΰϋΎΫΏĂÂÊÔƠƯăâêôơư一二三四五六七八九十百千上下左右中大小月日年早木林山川土空田天生花草虫犬人名女男子目耳口手足見音力気円入出立休先夕本文字学校村町森正水火玉王石竹糸貝車金雨赤青白数多少万半形太細広長点丸交光角計直線矢弱強高同親母父姉兄弟妹自友体毛頭顔首心時曜朝昼夜分週春夏秋冬今新古間方北南東西遠近前後内外場地国園谷野原里市京風雪雲池海岩星室戸家寺通門道話言答声聞語読書記紙画絵図工教晴思考知才理算作元食肉馬牛魚鳥羽鳴麦米茶色黄黒来行帰歩走止活店買売午汽弓回会組船明社切電毎合当台楽公引科歌刀番用何ĂÂÊÔƠƯăâêôơư1234567890‘?’“!”(%)[#]{@}/&<-+÷×=>$€£¥¢:;,.* •°·…±†‡æ«»¦¯—–~˜¨_øÞ¿▬▭▮▯┐└╛╟╚╔╘╒╓┘┌░▒▓○‼",glitchesFromString:!1,oneAtATime:!1,clearStart:!1});var b=function(t,e,n){return new y(t,n).write(e)},v=function(t,e){return new y(t,e)};module.exports={setGlitchedWriter:v,glitchWrite:b}; | ||
},{"regenerator-runtime":"KA2S"}]},{},["HLE4"], null) | ||
//# sourceMappingURL=/glitchedWriter.min.js.map |
{ | ||
"name": "glitched-writer", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "glitched text writer module", | ||
@@ -43,3 +43,4 @@ "author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>", | ||
"dependencies": { | ||
"lodash.debounce": "^4.0.8" | ||
"lodash.debounce": "^4.0.8", | ||
"regenerator-runtime": "^0.13.3" | ||
}, | ||
@@ -46,0 +47,0 @@ "babel": { |
@@ -47,2 +47,4 @@ # Glitched Writer | ||
| glitchesFromString | false | | ||
| oneAtATime | false | | ||
| clearStart | false | | ||
@@ -49,0 +51,0 @@ |
@@ -11,11 +11,6 @@ const { wait } = require('./utility.js') | ||
const displayWriter = setGlitchedWriter(textEl) | ||
wait(1200) | ||
.then(() => | ||
glitchWrite(textEl, 'my old friend.', { | ||
stepsMin: 7, | ||
stepsMax: 10, | ||
glitches: '', | ||
glitchesFromString: true, | ||
}), | ||
) | ||
.then(() => displayWriter.write('my old friend.')) | ||
.then(() => wait(1200)) | ||
@@ -29,8 +24,2 @@ .then(() => | ||
const displayWriter = setGlitchedWriter(textEl, { | ||
ghostLettersProbability: 0, | ||
maxGhostLetters: 0, | ||
glitches: '', | ||
}) | ||
inputEl.addEventListener( | ||
@@ -37,0 +26,0 @@ 'input', |
Sorry, the diff of this file is not supported yet
94060
755
59
2
+ Addedregenerator-runtime@^0.13.3
+ Addedregenerator-runtime@0.13.11(transitive)