glitched-writer
Advanced tools
Comparing version 2.0.20 to 2.0.21
@@ -118,3 +118,3 @@ "use strict"; | ||
return this.play({ | ||
reverse: this.options.oneAtATime && (writeOptions === null || writeOptions === void 0 ? void 0 : writeOptions.erase), | ||
reverse: this.options.oneAtATime !== 0 && (writeOptions === null || writeOptions === void 0 ? void 0 : writeOptions.erase), | ||
}); | ||
@@ -166,17 +166,37 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const playList = [], { charTable } = this, { length } = charTable; | ||
const playList = [], { charTable } = this; | ||
if (this.state.isTyping) | ||
return this.getWriterData('ERROR', `The writer is already typing "${this.goalString}".`); | ||
this.state.play(); | ||
if (this.options.oneAtATime) { | ||
const reverse = (_a = playOptions === null || playOptions === void 0 ? void 0 : playOptions.reverse) !== null && _a !== void 0 ? _a : false; | ||
let i = reverse ? length - 1 : 0, lastResult = true; | ||
const loop = () => __awaiter(this, void 0, void 0, function* () { | ||
lastResult = yield charTable[i].type(); | ||
reverse ? i-- : i++; | ||
/** | ||
* ONE AT A TIME | ||
*/ | ||
if (this.options.oneAtATime > 0) { | ||
const reverse = (_a = playOptions === null || playOptions === void 0 ? void 0 : playOptions.reverse) !== null && _a !== void 0 ? _a : false, charTableCopy = reverse ? [...charTable] : [...charTable].reverse(); | ||
// Char executor - runs a loop, typing one char at a time | ||
// It is possible to run multiple of them at the same time | ||
const executor = () => __awaiter(this, void 0, void 0, function* () { | ||
let lastResult = true, ended = false; | ||
const loop = () => __awaiter(this, void 0, void 0, function* () { | ||
var _b; | ||
const lastChar = charTableCopy.pop(); | ||
if (!lastChar) | ||
ended = true; | ||
else | ||
lastResult = (_b = (yield lastChar.type())) !== null && _b !== void 0 ? _b : false; | ||
}); | ||
yield utils_1.promiseWhile(() => !ended && lastResult && !this.state.isPaused, loop); | ||
return lastResult; | ||
}); | ||
yield utils_1.promiseWhile(() => utils_1.isInRange(0, i, length) && lastResult && !this.state.isPaused, loop); | ||
return this.returnResult(lastResult); | ||
// Add as many executors as needed to the playList | ||
for (let n = 0; n < this.options.oneAtATime; n++) { | ||
playList.push(executor()); | ||
} | ||
} | ||
charTable.forEach(char => playList.push(char.type())); | ||
/** | ||
* NORMAL | ||
*/ | ||
// Add every char .type() at once. | ||
else | ||
charTable.forEach(char => playList.push(char.type())); | ||
try { | ||
@@ -183,0 +203,0 @@ const finished = (yield Promise.all(playList)).every(result => result); |
@@ -11,3 +11,3 @@ import { ConstructorOptions, OptionsFields, RangeOrNumber } from './types'; | ||
glyphsFromString: boolean; | ||
oneAtATime: boolean; | ||
oneAtATime: number; | ||
html: boolean; | ||
@@ -14,0 +14,0 @@ letterize: boolean; |
@@ -8,3 +8,3 @@ "use strict"; | ||
constructor(writer, options) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; | ||
this.steps = (_a = options.steps) !== null && _a !== void 0 ? _a : presets_1.presets.default.steps; | ||
@@ -19,11 +19,14 @@ this.interval = (_b = options.interval) !== null && _b !== void 0 ? _b : presets_1.presets.default.interval; | ||
(_h = options.glyphsFromString) !== null && _h !== void 0 ? _h : presets_1.presets.default.glyphsFromString; | ||
this.oneAtATime = (_j = options.oneAtATime) !== null && _j !== void 0 ? _j : presets_1.presets.default.oneAtATime; | ||
this.html = (_k = options.html) !== null && _k !== void 0 ? _k : presets_1.presets.default.html; | ||
this.letterize = (_l = options.letterize) !== null && _l !== void 0 ? _l : presets_1.presets.default.letterize; | ||
if (Number.isInteger(options.oneAtATime)) | ||
this.oneAtATime = options.oneAtATime; | ||
else | ||
this.oneAtATime = options.oneAtATime ? 1 : 0; | ||
this.html = (_j = options.html) !== null && _j !== void 0 ? _j : presets_1.presets.default.html; | ||
this.letterize = (_k = options.letterize) !== null && _k !== void 0 ? _k : presets_1.presets.default.letterize; | ||
if (typeof document === 'undefined') | ||
this.letterize = false; | ||
this.endless = (_m = options.endless) !== null && _m !== void 0 ? _m : presets_1.presets.default.endless; | ||
this.startFrom = (_o = options.startFrom) !== null && _o !== void 0 ? _o : presets_1.presets.default.startFrom; | ||
this.endless = (_l = options.endless) !== null && _l !== void 0 ? _l : presets_1.presets.default.endless; | ||
this.startFrom = (_m = options.startFrom) !== null && _m !== void 0 ? _m : presets_1.presets.default.startFrom; | ||
this.writer = writer; | ||
this.fillSpace = (_p = options.fillSpace) !== null && _p !== void 0 ? _p : presets_1.presets.default.fillSpace; | ||
this.fillSpace = (_o = options.fillSpace) !== null && _o !== void 0 ? _o : presets_1.presets.default.fillSpace; | ||
} | ||
@@ -30,0 +33,0 @@ set glyphs(glyphs) { |
@@ -20,3 +20,3 @@ import { ConstructorOptions, RangeOrNumber } from './types'; | ||
glyphsFromString: boolean; | ||
oneAtATime: boolean; | ||
oneAtATime: number; | ||
html: boolean; | ||
@@ -23,0 +23,0 @@ fillSpace: boolean; |
@@ -22,3 +22,3 @@ "use strict"; | ||
glyphsFromString: false, | ||
oneAtATime: false, | ||
oneAtATime: 0, | ||
html: false, | ||
@@ -25,0 +25,0 @@ fillSpace: true, |
@@ -18,3 +18,3 @@ import GlitchedWriter from './index'; | ||
glyphsFromString: boolean; | ||
oneAtATime: boolean; | ||
oneAtATime: number; | ||
html: boolean; | ||
@@ -28,2 +28,3 @@ letterize: boolean; | ||
fillSpace?: boolean; | ||
oneAtATime?: number | boolean; | ||
}>; | ||
@@ -30,0 +31,0 @@ export interface HTMLWriterElement extends Element { |
@@ -83,5 +83,5 @@ "use strict"; | ||
exports.isSpecialChar = isSpecialChar; | ||
const findHTMLPattern = '(&#?[0-9a-zA-Z]{2,6};)|(<style.+?>.+?</style>|<script.+?>.+?</script>|<(?:!|/?[a-zA-Z]+).*?/?>)'; | ||
const findHTMLPattern = '(&(?:[a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});)|(<style.+?>.+?</style>|<script.+?>.+?</script>|<(?:!|/?[a-zA-Z]+).*?/?>)'; | ||
function htmlToArray(string) { | ||
const reg = new RegExp(findHTMLPattern, 'g'), resultArray = []; | ||
const reg = new RegExp(findHTMLPattern, 'gi'), resultArray = []; | ||
let find, lastIndex = 0; | ||
@@ -88,0 +88,0 @@ // eslint-disable-next-line no-cond-assign |
@@ -15,3 +15,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import Emiter from './emiter'; | ||
import { wait, promiseWhile, isInRange, htmlToArray, filterHtml, arrayOfTheSame, stringToLetterItems, } from './utils'; | ||
import { wait, promiseWhile, htmlToArray, filterHtml, arrayOfTheSame, stringToLetterItems, } from './utils'; | ||
import { presets, glyphs } from './presets'; | ||
@@ -110,3 +110,3 @@ export default class GlitchedWriter { | ||
return this.play({ | ||
reverse: this.options.oneAtATime && (writeOptions === null || writeOptions === void 0 ? void 0 : writeOptions.erase), | ||
reverse: this.options.oneAtATime !== 0 && (writeOptions === null || writeOptions === void 0 ? void 0 : writeOptions.erase), | ||
}); | ||
@@ -158,17 +158,37 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const playList = [], { charTable } = this, { length } = charTable; | ||
const playList = [], { charTable } = this; | ||
if (this.state.isTyping) | ||
return this.getWriterData('ERROR', `The writer is already typing "${this.goalString}".`); | ||
this.state.play(); | ||
if (this.options.oneAtATime) { | ||
const reverse = (_a = playOptions === null || playOptions === void 0 ? void 0 : playOptions.reverse) !== null && _a !== void 0 ? _a : false; | ||
let i = reverse ? length - 1 : 0, lastResult = true; | ||
const loop = () => __awaiter(this, void 0, void 0, function* () { | ||
lastResult = yield charTable[i].type(); | ||
reverse ? i-- : i++; | ||
/** | ||
* ONE AT A TIME | ||
*/ | ||
if (this.options.oneAtATime > 0) { | ||
const reverse = (_a = playOptions === null || playOptions === void 0 ? void 0 : playOptions.reverse) !== null && _a !== void 0 ? _a : false, charTableCopy = reverse ? [...charTable] : [...charTable].reverse(); | ||
// Char executor - runs a loop, typing one char at a time | ||
// It is possible to run multiple of them at the same time | ||
const executor = () => __awaiter(this, void 0, void 0, function* () { | ||
let lastResult = true, ended = false; | ||
const loop = () => __awaiter(this, void 0, void 0, function* () { | ||
var _b; | ||
const lastChar = charTableCopy.pop(); | ||
if (!lastChar) | ||
ended = true; | ||
else | ||
lastResult = (_b = (yield lastChar.type())) !== null && _b !== void 0 ? _b : false; | ||
}); | ||
yield promiseWhile(() => !ended && lastResult && !this.state.isPaused, loop); | ||
return lastResult; | ||
}); | ||
yield promiseWhile(() => isInRange(0, i, length) && lastResult && !this.state.isPaused, loop); | ||
return this.returnResult(lastResult); | ||
// Add as many executors as needed to the playList | ||
for (let n = 0; n < this.options.oneAtATime; n++) { | ||
playList.push(executor()); | ||
} | ||
} | ||
charTable.forEach(char => playList.push(char.type())); | ||
/** | ||
* NORMAL | ||
*/ | ||
// Add every char .type() at once. | ||
else | ||
charTable.forEach(char => playList.push(char.type())); | ||
try { | ||
@@ -175,0 +195,0 @@ const finished = (yield Promise.all(playList)).every(result => result); |
@@ -11,3 +11,3 @@ import { ConstructorOptions, OptionsFields, RangeOrNumber } from './types'; | ||
glyphsFromString: boolean; | ||
oneAtATime: boolean; | ||
oneAtATime: number; | ||
html: boolean; | ||
@@ -14,0 +14,0 @@ letterize: boolean; |
@@ -6,3 +6,3 @@ // eslint-disable-next-line import/no-extraneous-dependencies | ||
constructor(writer, options) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; | ||
this.steps = (_a = options.steps) !== null && _a !== void 0 ? _a : presets.default.steps; | ||
@@ -17,11 +17,14 @@ this.interval = (_b = options.interval) !== null && _b !== void 0 ? _b : presets.default.interval; | ||
(_h = options.glyphsFromString) !== null && _h !== void 0 ? _h : presets.default.glyphsFromString; | ||
this.oneAtATime = (_j = options.oneAtATime) !== null && _j !== void 0 ? _j : presets.default.oneAtATime; | ||
this.html = (_k = options.html) !== null && _k !== void 0 ? _k : presets.default.html; | ||
this.letterize = (_l = options.letterize) !== null && _l !== void 0 ? _l : presets.default.letterize; | ||
if (Number.isInteger(options.oneAtATime)) | ||
this.oneAtATime = options.oneAtATime; | ||
else | ||
this.oneAtATime = options.oneAtATime ? 1 : 0; | ||
this.html = (_j = options.html) !== null && _j !== void 0 ? _j : presets.default.html; | ||
this.letterize = (_k = options.letterize) !== null && _k !== void 0 ? _k : presets.default.letterize; | ||
if (typeof document === 'undefined') | ||
this.letterize = false; | ||
this.endless = (_m = options.endless) !== null && _m !== void 0 ? _m : presets.default.endless; | ||
this.startFrom = (_o = options.startFrom) !== null && _o !== void 0 ? _o : presets.default.startFrom; | ||
this.endless = (_l = options.endless) !== null && _l !== void 0 ? _l : presets.default.endless; | ||
this.startFrom = (_m = options.startFrom) !== null && _m !== void 0 ? _m : presets.default.startFrom; | ||
this.writer = writer; | ||
this.fillSpace = (_p = options.fillSpace) !== null && _p !== void 0 ? _p : presets.default.fillSpace; | ||
this.fillSpace = (_o = options.fillSpace) !== null && _o !== void 0 ? _o : presets.default.fillSpace; | ||
} | ||
@@ -28,0 +31,0 @@ set glyphs(glyphs) { |
@@ -20,3 +20,3 @@ import { ConstructorOptions, RangeOrNumber } from './types'; | ||
glyphsFromString: boolean; | ||
oneAtATime: boolean; | ||
oneAtATime: number; | ||
html: boolean; | ||
@@ -23,0 +23,0 @@ fillSpace: boolean; |
@@ -19,3 +19,3 @@ export const glyphs = { | ||
glyphsFromString: false, | ||
oneAtATime: false, | ||
oneAtATime: 0, | ||
html: false, | ||
@@ -22,0 +22,0 @@ fillSpace: true, |
@@ -18,3 +18,3 @@ import GlitchedWriter from './index'; | ||
glyphsFromString: boolean; | ||
oneAtATime: boolean; | ||
oneAtATime: number; | ||
html: boolean; | ||
@@ -28,2 +28,3 @@ letterize: boolean; | ||
fillSpace?: boolean; | ||
oneAtATime?: number | boolean; | ||
}>; | ||
@@ -30,0 +31,0 @@ export interface HTMLWriterElement extends Element { |
@@ -64,5 +64,5 @@ /* eslint-disable no-unused-vars */ | ||
export const isSpecialChar = (l) => ['\t', '\n', '\r', '\f', '\v', '', ' '].includes(l); | ||
const findHTMLPattern = '(&#?[0-9a-zA-Z]{2,6};)|(<style.+?>.+?</style>|<script.+?>.+?</script>|<(?:!|/?[a-zA-Z]+).*?/?>)'; | ||
const findHTMLPattern = '(&(?:[a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});)|(<style.+?>.+?</style>|<script.+?>.+?</script>|<(?:!|/?[a-zA-Z]+).*?/?>)'; | ||
export function htmlToArray(string) { | ||
const reg = new RegExp(findHTMLPattern, 'g'), resultArray = []; | ||
const reg = new RegExp(findHTMLPattern, 'gi'), resultArray = []; | ||
let find, lastIndex = 0; | ||
@@ -69,0 +69,0 @@ // eslint-disable-next-line no-cond-assign |
@@ -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}),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,fillSpace:!1,startFrom:"erase",glyphsFromString:!0},typewriter:{interval:[40,100],initialDelay:[0,0],steps:[0,1],changeChance:1,maxGhosts:0,glyphs:"",glyphsFromString:!0,oneAtATime:!0,fillSpace:!1,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;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=e.glyphs)&&void 0!==l?l:d.default.glyphs,this.glyphsFromString=null!==(a=e.glyphsFromString)&&void 0!==a?a:d.default.glyphsFromString,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,"undefined"==typeof document&&(this.letterize=!1),this.endless=null!==(p=e.endless)&&void 0!==p?p:d.default.endless,this.startFrom=null!==(f=e.startFrom)&&void 0!==f?f:d.default.startFrom,this.writer=t,this.fillSpace=null!==(m=e.fillSpace)&&void 0!==m?m:d.default.fillSpace}set glyphs(t){this.glyphsString=function(t){let e;return e="string"==typeof t?t:t.length?t.join(""):Array.from(t).join(""),e}(t),this.setCharset()}set fillSpace(t){this.space=t?" ":""}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 ghost(){var t,e;return null!==(t=(e=this.ghostCharset)[s(0,e.length,"floor")])&&void 0!==t?t:""}setCharset(){let t=this.glyphsString;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.ghost)}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.ghost;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="",this.htmlElement="string"==typeof t?null!==(n=document.querySelector(t))&&void 0!==n?n:void 0:null!=t?t:void 0,this.htmlElement&&(this.htmlElement.$writer=this),"string"==typeof e?this.preset=e:this.setOptions(null!=e?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}extendOptions(t){this.setOptions(Object.assign(Object.assign({},this.options),t))}setOptions(t){this.options=new f(this,t)}set preset(t){this.options=new f(this,d[t])}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})()})); | ||
!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="(&(?:[a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,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:0,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,fillSpace:!1,startFrom:"erase",glyphsFromString:!0},typewriter:{interval:[40,100],initialDelay:[0,0],steps:[0,1],changeChance:1,maxGhosts:0,glyphs:"",glyphsFromString:!0,oneAtATime:!0,fillSpace:!1,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;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=e.glyphs)&&void 0!==l?l:d.default.glyphs,this.glyphsFromString=null!==(a=e.glyphsFromString)&&void 0!==a?a:d.default.glyphsFromString,Number.isInteger(e.oneAtATime)?this.oneAtATime=e.oneAtATime:this.oneAtATime=e.oneAtATime?1:0,this.html=null!==(c=e.html)&&void 0!==c?c:d.default.html,this.letterize=null!==(g=e.letterize)&&void 0!==g?g:d.default.letterize,"undefined"==typeof document&&(this.letterize=!1),this.endless=null!==(u=e.endless)&&void 0!==u?u:d.default.endless,this.startFrom=null!==(p=e.startFrom)&&void 0!==p?p:d.default.startFrom,this.writer=t,this.fillSpace=null!==(f=e.fillSpace)&&void 0!==f?f:d.default.fillSpace}set glyphs(t){this.glyphsString=function(t){let e;return e="string"==typeof t?t:t.length?t.join(""):Array.from(t).join(""),e}(t),this.setCharset()}set fillSpace(t){this.space=t?" ":""}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 ghost(){var t,e;return null!==(t=(e=this.ghostCharset)[s(0,e.length,"floor")])&&void 0!==t?t:""}setCharset(){let t=this.glyphsString;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.ghost)}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.ghost;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="",this.htmlElement="string"==typeof t?null!==(n=document.querySelector(t))&&void 0!==n?n:void 0:null!=t?t:void 0,this.htmlElement&&(this.htmlElement.$writer=this),"string"==typeof e?this.preset=e:this.setOptions(null!=e?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}extendOptions(t){this.setOptions(Object.assign(Object.assign({},this.options),t))}setOptions(t){this.options=new f(this,t)}set preset(t){this.options=new f(this,d[t])}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:0!==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;if(this.state.isTyping)return this.getWriterData("ERROR",`The writer is already typing "${this.goalString}".`);if(this.state.play(),this.options.oneAtATime>0){const n=null!==(e=null==t?void 0:t.reverse)&&void 0!==e&&e?[...i]:[...i].reverse(),h=()=>C(this,void 0,void 0,(function*(){let t=!0,e=!1;return yield r((()=>!e&&t&&!this.state.isPaused),(()=>C(this,void 0,void 0,(function*(){var s;const i=n.pop();i?t=null!==(s=yield i.type())&&void 0!==s&&s:e=!0})))),t}));for(let t=0;t<this.options.oneAtATime;t++)s.push(h())}else 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,"gi"),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.20", | ||
"version": "2.0.21", | ||
"description": "Glitched, text writing module. Highly customizable settings. Decoding, decrypting, scrambling, or simply spelling out text.", | ||
@@ -28,3 +28,3 @@ "author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>", | ||
"build": "tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && grunt build", | ||
"prepublish": "npm run build && npm version patch", | ||
"prepublishOnly": "npm run build && npm version patch", | ||
"postpublish": "git push && git push --tags" | ||
@@ -31,0 +31,0 @@ }, |
@@ -24,4 +24,6 @@ # Glitched Writer | ||
- Possible to write text with **html tags** in it and letterize it into many **span** elements. | ||
- Handles **html tags** & **html entities** (e.g. \<br/\>, \<a href="#"\>link\</a\>, \;, \&). | ||
- Can letterize string it into many **span** elements inside the parent element. | ||
- Written fully in **Typescript**. | ||
@@ -344,3 +346,3 @@ | ||
startFrom?: 'matching' | 'previous' | 'erase', // 'matching' | ||
oneAtATime?: boolean, // false | ||
oneAtATime?: boolean | number, // false | ||
html?: boolean, // false | ||
@@ -384,3 +386,3 @@ letterize?: boolean, // false | ||
- **oneAtATime** - If writing should take place from left-to-right, letter-by-letter or normally: all-at-once. | ||
- **oneAtATime** - Without this option enabled, letters in your string will animate all at once. Enabling this option, by setting it to **true** or any **intiger larger than 0**, will cause the string to be written from left to right (startFrom: 'erase', will make it go form right to left - when erasing). Number value, signifies number of letters being typed at one time. | ||
@@ -391,14 +393,7 @@ - **html** - _Potentially dangerous option._ If true, written string will be injected as html, not text content. It provides advanced text formating with html tags and more. But be sure to NOT enable it on user-provided content. | ||
- **fillSpace** - Normally if letter gets erased it actually gets replaced with space instead - to make words appear from and disappear into space, rather then sticking to the rest of the words. Set to false if you want to disable this. | ||
- **fillSpace** - With this **enabled** if letter gets erased ny replacing with space - to keep the same "width" of previous string, and to make letters _"disappear in space"_. If **disabled**, every letter will "stick" to the rest. To make it more clear (hopefully), here is an example "frame" of writing: **"Something farely long"** -> **"Short String"**. | ||
- **endless** - It will make the animation endless. _But why?_ Well, you can disable this option while the animation is running _(writer.options.endless = false)_ and finish the animation. | ||
- false - "XOSh8rt S3rinFv" | ||
- true - " X OSh8rt S3rinF v " | ||
## Links: | ||
- [GitHub](https://github.com/thetarnav/glitched-writer 'GitHub') | ||
- [npm](https://www.npmjs.com/package/glitched-writer 'npm') | ||
- [JSDelivr](https://www.jsdelivr.com/package/npm/glitched-writer 'JSDelivr') | ||
- [Codepen DEMO](https://codepen.io/thetarnav/pen/MWWyPzY 'Codepen DEMO') | ||
- **endless** - It will make the animation endless. _But why?_ Well, you can disable this option while the animation is running _(writer.options.endless = false)_ and finish the animation when you want. |
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
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
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
249913
2359
396