glitched-writer
Advanced tools
Comparing version 2.0.27 to 2.0.28
@@ -9,7 +9,9 @@ "use strict"; | ||
function setupCharTable() { | ||
const { charTable, options } = this; | ||
// For "clear" mode char table will be prepared as starting from blank | ||
const from = this.options.mode === 'clear' && this.state.finished | ||
? '' | ||
: this.previousString; | ||
this.options.mode === 'matching' | ||
const from = options.mode === 'clear' && this.state.finished ? '' : this.previousString; | ||
// Clear Char Table -> stop all chars and remove them from char table | ||
charTable.forEach(char => (char.stop = true)); | ||
this.charTable = []; | ||
options.mode === 'matching' | ||
? createMatching.call(this, from) | ||
@@ -58,3 +60,3 @@ : createPrevious.call(this, from); | ||
: utils_1.stringToLetterItems(goalText), diff = Math.max(0, from.length - goalArray.length); | ||
if (this.options.oneAtATime) | ||
if (options.oneAtATime) | ||
return goalArray.concat(utils_1.stringToLetterItems(utils_1.arrayOfTheSame('', diff))); | ||
@@ -65,6 +67,4 @@ const nBefore = Math.ceil(diff / 2), nAfter = Math.floor(diff / 2); | ||
function setChar(i, l, gl, ghosts) { | ||
const { charTable, options } = this, char = charTable[i]; | ||
char | ||
? char.reset(l !== null && l !== void 0 ? l : '', gl.value || options.space, ghosts, gl.type, i) | ||
: charTable.push(new char_1.default(this, l !== null && l !== void 0 ? l : '', gl.value || options.space, ghosts, gl.type, i)); | ||
const { charTable, options } = this; | ||
charTable.push(new char_1.default(this, l !== null && l !== void 0 ? l : '', gl.value || options.space, ghosts, gl.type, i)); | ||
} | ||
@@ -71,0 +71,0 @@ function removeExtraChars(charTable, from) { |
@@ -30,2 +30,3 @@ "use strict"; | ||
const animator_1 = __importDefault(require("./modules/animator")); | ||
const queue_1 = __importDefault(require("./modules/queue")); | ||
class GlitchedWriter { | ||
@@ -37,3 +38,2 @@ /** | ||
* @param options Options object (eg. { html: true, ... }) OR preset name (eg. 'zalgo'). | ||
* @param onStepCallback Callback, that will be triggered on every step. Params passed: string & writer data. | ||
* @param onFinishCallback Callback, that will be triggered when each writing finishes. Params passed: string & writer data. | ||
@@ -86,13 +86,34 @@ */ | ||
} | ||
/** | ||
* Main function of Glitched Writer. It orders writer to start typing passed string. Can be called multiple times after each other, or even during writing. | ||
* @param string text, that will get written. | ||
* @returns Promise, with writer data result | ||
*/ | ||
write(string) { | ||
write(texts, queueInterval, loop) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.manageWriting(string); | ||
if (this.queue) { | ||
this.queue.stop(); | ||
delete this.queue; | ||
} | ||
if (typeof texts === 'string') | ||
return this.manageWriting(texts); | ||
this.queryWrite(texts, queueInterval, loop); | ||
}); | ||
} | ||
/** | ||
* Order Glitched writer to write sequence of texts. | ||
* @param texts - Array of strings to write. | ||
* | ||
* You can also pass selector or a html element. | ||
* Paragraph children content will make the array of texts | ||
* @param queueInterval - Time to wait between writing each texts [ms] | ||
* @param loop - boolean | Callback | number - What to do when the queue has ended. | ||
* - false -> stop; | ||
* - true -> continue looping; | ||
* - Callback -> stop and fire the callback. | ||
* - number -> wait number ms and than continue | ||
*/ | ||
queryWrite(texts, queueInterval, loop) { | ||
if (this.queue) { | ||
this.queue.stop(); | ||
delete this.queue; | ||
} | ||
this.queue = new queue_1.default(this, texts, queueInterval, loop); | ||
} | ||
/** | ||
* Add text to end method. Orders writer to write same string as previous, but with this added at the end. | ||
@@ -122,2 +143,23 @@ * @param string text that will get added | ||
/** | ||
* Resume last writing order. | ||
* @returns Promise, with writer data result | ||
*/ | ||
play() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.state.isPaused) | ||
return this.getWriterData('ERROR', "The writer isn't paused."); | ||
if (this.queue) { | ||
this.queue.resume(); | ||
return this.getWriterData('SUCCESS', 'The queue was resumed'); | ||
} | ||
return this.manageWriting(null); | ||
}); | ||
} | ||
/** | ||
* Pause current writer task. | ||
*/ | ||
pause() { | ||
this.state.pause(); | ||
} | ||
/** | ||
* Shorthand for changing endless option value | ||
@@ -160,17 +202,2 @@ * @param bool goal state | ||
// } | ||
/** | ||
* Resume last writing order. | ||
* @returns Promise, with writer data result | ||
*/ | ||
play() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.manageWriting(null); | ||
}); | ||
} | ||
/** | ||
* Pause current writer task. | ||
*/ | ||
pause() { | ||
this.state.pause(); | ||
} | ||
manageWriting(text) { | ||
@@ -181,3 +208,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
// Erasing first | ||
if (this.options.mode === 'erase' && | ||
if (['erase_smart', 'erase'].includes(this.options.mode) && | ||
(this.state.finished || this.state.erasing)) { | ||
@@ -255,8 +282,11 @@ this.state.erasing = true; | ||
let result = ''; | ||
for (let i = 0; i < goal.length; i++) { | ||
const gl = goal[i], pl = (_a = previous[i]) !== null && _a !== void 0 ? _a : ''; | ||
if (gl === pl) | ||
result += pl; | ||
else | ||
break; | ||
if (this.options.mode === 'erase_smart') { | ||
// Do not erase matching with previous letters | ||
for (let i = 0; i < goal.length; i++) { | ||
const gl = goal[i], pl = (_a = previous[i]) !== null && _a !== void 0 ? _a : ''; | ||
if (gl === pl) | ||
result += pl; | ||
else | ||
break; | ||
} | ||
} | ||
@@ -279,5 +309,7 @@ const diff = Math.max(goal.length - result.length, 0); | ||
*/ | ||
function glitchWrite(string, htmlElement, options, onFinishCallback) { | ||
function glitchWrite(string, htmlElement, options, onStepCallback, onFinishCallback) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const writer = new GlitchedWriter(htmlElement, options, onFinishCallback); | ||
if (onStepCallback) | ||
writer.addCallback('step', onStepCallback); | ||
return writer.write(string); | ||
@@ -291,3 +323,2 @@ }); | ||
* @param options Options object (eg. { html: true, ... }) OR preset name (eg. 'zalgo'). | ||
* @param onStepCallback Callback, that will be triggered on every step. Params passed: string & writer data. | ||
* @param onFinishCallback Callback, that will be triggered when each writing finishes. Params passed: string & writer data. | ||
@@ -294,0 +325,0 @@ * @returns GlitchedWriter Class Instance |
@@ -19,16 +19,3 @@ "use strict"; | ||
this.writer = writer; | ||
this.setProps(l, gl, initialGhosts, specialType, index); | ||
if (writer.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(l, gl, initialGhosts = '', specialType, index) { | ||
const { options } = this.writer; | ||
const { options } = writer; | ||
this.index = index; | ||
@@ -47,7 +34,12 @@ this.l = l; | ||
(options.ghostChance + options.changeChance) / 3.7; | ||
} | ||
reset(l, gl, initialGhosts = '', specialType, index) { | ||
this.setProps(l, gl, initialGhosts, specialType, index); | ||
if (this.els) | ||
if (writer.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'; | ||
} | ||
} | ||
@@ -54,0 +46,0 @@ get string() { |
@@ -54,3 +54,3 @@ "use strict"; | ||
fillSpace: false, | ||
mode: 'erase', | ||
mode: 'erase_smart', | ||
}, | ||
@@ -57,0 +57,0 @@ terminal: { |
import Char from '../modules/char'; | ||
import { arrayOfTheSame, htmlToArray, stringToLetterItems as textToLetterItems, } from '../utils'; | ||
export default function setupCharTable() { | ||
const { charTable, options } = this; | ||
// For "clear" mode char table will be prepared as starting from blank | ||
const from = this.options.mode === 'clear' && this.state.finished | ||
? '' | ||
: this.previousString; | ||
this.options.mode === 'matching' | ||
const from = options.mode === 'clear' && this.state.finished ? '' : this.previousString; | ||
// Clear Char Table -> stop all chars and remove them from char table | ||
charTable.forEach(char => (char.stop = true)); | ||
this.charTable = []; | ||
options.mode === 'matching' | ||
? createMatching.call(this, from) | ||
@@ -51,3 +53,3 @@ : createPrevious.call(this, from); | ||
: textToLetterItems(goalText), diff = Math.max(0, from.length - goalArray.length); | ||
if (this.options.oneAtATime) | ||
if (options.oneAtATime) | ||
return goalArray.concat(textToLetterItems(arrayOfTheSame('', diff))); | ||
@@ -58,6 +60,4 @@ const nBefore = Math.ceil(diff / 2), nAfter = Math.floor(diff / 2); | ||
function setChar(i, l, gl, ghosts) { | ||
const { charTable, options } = this, char = charTable[i]; | ||
char | ||
? char.reset(l !== null && l !== void 0 ? l : '', gl.value || options.space, ghosts, gl.type, i) | ||
: charTable.push(new Char(this, l !== null && l !== void 0 ? l : '', gl.value || options.space, ghosts, gl.type, i)); | ||
const { charTable, options } = this; | ||
charTable.push(new Char(this, l !== null && l !== void 0 ? l : '', gl.value || options.space, ghosts, gl.type, i)); | ||
} | ||
@@ -64,0 +64,0 @@ function removeExtraChars(charTable, from) { |
@@ -9,2 +9,3 @@ import Options from './modules/options'; | ||
import Animator from './modules/animator'; | ||
import Queue from './modules/queue'; | ||
export default class GlitchedWriter { | ||
@@ -16,2 +17,3 @@ htmlElement: HTMLWriterElement; | ||
animator: Animator; | ||
queue?: Queue; | ||
charTable: Char[]; | ||
@@ -26,3 +28,2 @@ goalText: string; | ||
* @param options Options object (eg. { html: true, ... }) OR preset name (eg. 'zalgo'). | ||
* @param onStepCallback Callback, that will be triggered on every step. Params passed: string & writer data. | ||
* @param onFinishCallback Callback, that will be triggered when each writing finishes. Params passed: string & writer data. | ||
@@ -39,7 +40,32 @@ */ | ||
* Main function of Glitched Writer. It orders writer to start typing passed string. Can be called multiple times after each other, or even during writing. | ||
* @param string text, that will get written. | ||
* @param text text, that will get written. | ||
* @returns Promise, with writer data result | ||
*/ | ||
write(string: string): Promise<WriterDataResponse>; | ||
write(text: string): Promise<WriterDataResponse>; | ||
/** | ||
* Order Glitched writer to write sequence of texts. In a loop or not. | ||
* @param texts - Array of strings to write | ||
* @param queueInterval - Time to wait between writing each texts [ms] | ||
* @param loop - boolean | Callback | number - What to do when the queue has ended. | ||
* - false -> stop; | ||
* - true -> continue looping; | ||
* - Callback -> stop and fire the callback. | ||
* - number -> wait number ms and than continue | ||
*/ | ||
write(texts: string[], queueInterval?: number, loop?: boolean | Callback | number): Promise<void>; | ||
/** | ||
* Order Glitched writer to write sequence of texts. | ||
* @param texts - Array of strings to write. | ||
* | ||
* You can also pass selector or a html element. | ||
* Paragraph children content will make the array of texts | ||
* @param queueInterval - Time to wait between writing each texts [ms] | ||
* @param loop - boolean | Callback | number - What to do when the queue has ended. | ||
* - false -> stop; | ||
* - true -> continue looping; | ||
* - Callback -> stop and fire the callback. | ||
* - number -> wait number ms and than continue | ||
*/ | ||
queryWrite(texts: string[] | HTMLElement | Element | string, queueInterval?: number, loop?: boolean | Callback | number): void; | ||
/** | ||
* Add text to end method. Orders writer to write same string as previous, but with this added at the end. | ||
@@ -57,2 +83,11 @@ * @param string text that will get added | ||
/** | ||
* Resume last writing order. | ||
* @returns Promise, with writer data result | ||
*/ | ||
play(): Promise<WriterDataResponse>; | ||
/** | ||
* Pause current writer task. | ||
*/ | ||
pause(): void; | ||
/** | ||
* Shorthand for changing endless option value | ||
@@ -76,16 +111,7 @@ * @param bool goal state | ||
removeCallback(type: CallbackType, callback: Callback): void; | ||
/** | ||
* Resume last writing order. | ||
* @returns Promise, with writer data result | ||
*/ | ||
play(): Promise<WriterDataResponse>; | ||
/** | ||
* Pause current writer task. | ||
*/ | ||
pause(): void; | ||
private manageWriting; | ||
manageWriting(text: string | null): Promise<WriterDataResponse>; | ||
private preparePropertiesBeforeWrite; | ||
private playChT; | ||
private returnResult; | ||
private getWriterData; | ||
getWriterData(status?: WriterDataResponse['status'], message?: WriterDataResponse['message'], error?: WriterDataResponse['error']): WriterDataResponse; | ||
private genGoalStringToErase; | ||
@@ -102,3 +128,3 @@ } | ||
*/ | ||
export declare function glitchWrite(string: string, htmlElement?: HTMLElement | Element | null | string, options?: CustomOptions | PresetName | null, onFinishCallback?: Callback): Promise<WriterDataResponse>; | ||
export declare function glitchWrite(string: string, htmlElement?: HTMLElement | Element | null | string, options?: CustomOptions | PresetName | null, onStepCallback?: Callback, onFinishCallback?: Callback): Promise<WriterDataResponse>; | ||
/** | ||
@@ -108,3 +134,2 @@ * A way to create new Writer without having to rely on defult export. | ||
* @param options Options object (eg. { html: true, ... }) OR preset name (eg. 'zalgo'). | ||
* @param onStepCallback Callback, that will be triggered on every step. Params passed: string & writer data. | ||
* @param onFinishCallback Callback, that will be triggered when each writing finishes. Params passed: string & writer data. | ||
@@ -111,0 +136,0 @@ * @returns GlitchedWriter Class Instance |
@@ -21,2 +21,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import Animator from './modules/animator'; | ||
import Queue from './modules/queue'; | ||
export default class GlitchedWriter { | ||
@@ -28,3 +29,2 @@ /** | ||
* @param options Options object (eg. { html: true, ... }) OR preset name (eg. 'zalgo'). | ||
* @param onStepCallback Callback, that will be triggered on every step. Params passed: string & writer data. | ||
* @param onFinishCallback Callback, that will be triggered when each writing finishes. Params passed: string & writer data. | ||
@@ -77,13 +77,34 @@ */ | ||
} | ||
/** | ||
* Main function of Glitched Writer. It orders writer to start typing passed string. Can be called multiple times after each other, or even during writing. | ||
* @param string text, that will get written. | ||
* @returns Promise, with writer data result | ||
*/ | ||
write(string) { | ||
write(texts, queueInterval, loop) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.manageWriting(string); | ||
if (this.queue) { | ||
this.queue.stop(); | ||
delete this.queue; | ||
} | ||
if (typeof texts === 'string') | ||
return this.manageWriting(texts); | ||
this.queryWrite(texts, queueInterval, loop); | ||
}); | ||
} | ||
/** | ||
* Order Glitched writer to write sequence of texts. | ||
* @param texts - Array of strings to write. | ||
* | ||
* You can also pass selector or a html element. | ||
* Paragraph children content will make the array of texts | ||
* @param queueInterval - Time to wait between writing each texts [ms] | ||
* @param loop - boolean | Callback | number - What to do when the queue has ended. | ||
* - false -> stop; | ||
* - true -> continue looping; | ||
* - Callback -> stop and fire the callback. | ||
* - number -> wait number ms and than continue | ||
*/ | ||
queryWrite(texts, queueInterval, loop) { | ||
if (this.queue) { | ||
this.queue.stop(); | ||
delete this.queue; | ||
} | ||
this.queue = new Queue(this, texts, queueInterval, loop); | ||
} | ||
/** | ||
* Add text to end method. Orders writer to write same string as previous, but with this added at the end. | ||
@@ -113,2 +134,23 @@ * @param string text that will get added | ||
/** | ||
* Resume last writing order. | ||
* @returns Promise, with writer data result | ||
*/ | ||
play() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.state.isPaused) | ||
return this.getWriterData('ERROR', "The writer isn't paused."); | ||
if (this.queue) { | ||
this.queue.resume(); | ||
return this.getWriterData('SUCCESS', 'The queue was resumed'); | ||
} | ||
return this.manageWriting(null); | ||
}); | ||
} | ||
/** | ||
* Pause current writer task. | ||
*/ | ||
pause() { | ||
this.state.pause(); | ||
} | ||
/** | ||
* Shorthand for changing endless option value | ||
@@ -151,17 +193,2 @@ * @param bool goal state | ||
// } | ||
/** | ||
* Resume last writing order. | ||
* @returns Promise, with writer data result | ||
*/ | ||
play() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.manageWriting(null); | ||
}); | ||
} | ||
/** | ||
* Pause current writer task. | ||
*/ | ||
pause() { | ||
this.state.pause(); | ||
} | ||
manageWriting(text) { | ||
@@ -172,3 +199,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
// Erasing first | ||
if (this.options.mode === 'erase' && | ||
if (['erase_smart', 'erase'].includes(this.options.mode) && | ||
(this.state.finished || this.state.erasing)) { | ||
@@ -246,8 +273,11 @@ this.state.erasing = true; | ||
let result = ''; | ||
for (let i = 0; i < goal.length; i++) { | ||
const gl = goal[i], pl = (_a = previous[i]) !== null && _a !== void 0 ? _a : ''; | ||
if (gl === pl) | ||
result += pl; | ||
else | ||
break; | ||
if (this.options.mode === 'erase_smart') { | ||
// Do not erase matching with previous letters | ||
for (let i = 0; i < goal.length; i++) { | ||
const gl = goal[i], pl = (_a = previous[i]) !== null && _a !== void 0 ? _a : ''; | ||
if (gl === pl) | ||
result += pl; | ||
else | ||
break; | ||
} | ||
} | ||
@@ -269,5 +299,7 @@ const diff = Math.max(goal.length - result.length, 0); | ||
*/ | ||
export function glitchWrite(string, htmlElement, options, onFinishCallback) { | ||
export function glitchWrite(string, htmlElement, options, onStepCallback, onFinishCallback) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const writer = new GlitchedWriter(htmlElement, options, onFinishCallback); | ||
if (onStepCallback) | ||
writer.addCallback('step', onStepCallback); | ||
return writer.write(string); | ||
@@ -280,3 +312,2 @@ }); | ||
* @param options Options object (eg. { html: true, ... }) OR preset name (eg. 'zalgo'). | ||
* @param onStepCallback Callback, that will be triggered on every step. Params passed: string & writer data. | ||
* @param onFinishCallback Callback, that will be triggered when each writing finishes. Params passed: string & writer data. | ||
@@ -283,0 +314,0 @@ * @returns GlitchedWriter Class Instance |
@@ -20,4 +20,2 @@ import GlitchedWriter from '../index'; | ||
constructor(writer: GlitchedWriter, l: string, gl: string, initialGhosts: string | undefined, specialType: LetterItem['type'], index: number); | ||
private setProps; | ||
reset(l: string, gl: string, initialGhosts: string | undefined, specialType: LetterItem['type'], index: number): void; | ||
get string(): string; | ||
@@ -24,0 +22,0 @@ get finished(): boolean; |
@@ -17,16 +17,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
this.writer = writer; | ||
this.setProps(l, gl, initialGhosts, specialType, index); | ||
if (writer.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(l, gl, initialGhosts = '', specialType, index) { | ||
const { options } = this.writer; | ||
const { options } = writer; | ||
this.index = index; | ||
@@ -45,7 +32,12 @@ this.l = l; | ||
(options.ghostChance + options.changeChance) / 3.7; | ||
} | ||
reset(l, gl, initialGhosts = '', specialType, index) { | ||
this.setProps(l, gl, initialGhosts, specialType, index); | ||
if (this.els) | ||
if (writer.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'; | ||
} | ||
} | ||
@@ -52,0 +44,0 @@ get string() { |
@@ -26,3 +26,3 @@ import { CustomOptions, OptionsFields } from '../types'; | ||
private baseGetDelay; | ||
get mode(): "normal" | "matching" | "erase" | "clear"; | ||
get mode(): "normal" | "matching" | "erase" | "erase_smart" | "clear"; | ||
get html(): boolean; | ||
@@ -29,0 +29,0 @@ get endless(): boolean; |
@@ -23,3 +23,3 @@ import { RangeOrNumber } from './types'; | ||
fillSpace: boolean; | ||
mode: "normal" | "matching" | "erase" | "clear"; | ||
mode: "normal" | "matching" | "erase" | "erase_smart" | "clear"; | ||
html: boolean; | ||
@@ -26,0 +26,0 @@ letterize: boolean; |
@@ -51,3 +51,3 @@ export const glyphs = { | ||
fillSpace: false, | ||
mode: 'erase', | ||
mode: 'erase_smart', | ||
}, | ||
@@ -54,0 +54,0 @@ terminal: { |
@@ -16,3 +16,3 @@ import GlitchedWriter from './index'; | ||
glyphsFromText: boolean; | ||
mode: 'matching' | 'normal' | 'erase' | 'clear'; | ||
mode: 'matching' | 'normal' | 'erase' | 'erase_smart' | 'clear'; | ||
html: boolean; | ||
@@ -19,0 +19,0 @@ letterize: boolean; |
@@ -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.GlitchedWriter=e():t.GlitchedWriter=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,{create:()=>F,default:()=>R,glitchWrite:()=>k,glyphs:()=>d,presets:()=>f,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 a=(t=.5)=>Math.random()<t,l=t=>({value:t}),c=t=>[...t].map(l),p="(&(?:[a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});)|(<style.+?>.+?</style>|<script.+?>.+?<\/script>|<(?:!|/?[a-zA-Z]+).*?/?>)",u=/(&(?:[a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});)|.\w+,*\.*"*\s?|\s+|\S+/gi;function g(t){const e=new RegExp(p,"g");return t.replace(e,"")}const d={nier:"一二三四五六七八九十百千上下左右中大小月日年早木林山川土空田天生花草虫犬人名女男子目耳口手足見音力気円入出立休先夕本文字学校村町森正水火玉王石竹糸貝車金雨赤青白数多少万半形太細広長点丸交光角計直線矢弱強高同親母父姉兄弟妹自友体毛頭顔首心時曜朝昼夜分週春夏秋冬今新古間方北南東西遠近前後内外場地国園谷野原里市京風雪雲池海岩星室戸家寺通門道話言答声聞語読書記紙画絵図工教晴思考知才理算作元食肉馬牛魚鳥羽鳴麦米茶色黄黒来行帰歩走止活店買売午汽弓回会組船明社切電毎合当台楽公引科歌刀番用何",full:"ABCDĐEFGHIJKLMNOPQRSTUVWXYZabcdđefghijklmnopqrstuvwxyzĄąĆ毿ŹźŃńóŁłАБВГҐДЂЕЁЄЖЗЅИІЇЙЈКЛЉМНЊОПРСТЋУЎФХЦЧЏШЩЪЫЬЭЮЯабвгґдђеёєжзѕиіїйјклљмнњопрстћуўфхцчџшщъыьэюяΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψωάΆέΈέΉίϊΐΊόΌύΰϋΎΫΏĂÂÊÔƠƯăâêôơư一二三四五六七八九十百千上下左右中大小月日年早木林山川土空田天生花草虫犬人名女男子目耳口手足見音力気円入出立休先夕本文字学校村町森正水火玉王石竹糸貝車金雨赤青白数多少万半形太細広長点丸交光角計直線矢弱強高同親母父姉兄弟妹自友体毛頭顔首心時曜朝昼夜分週春夏秋冬今新古間方北南東西遠近前後内外場地国園谷野原里市京風雪雲池海岩星室戸家寺通門道話言答声聞語読書記紙画絵図工教晴思考知才理算作元食肉馬牛魚鳥羽鳴麦米茶色黄黒来行帰歩走止活店買売午汽弓回会組船明社切電毎合当台楽公引科歌刀番用何ĂÂÊÔƠƯăâêôơư1234567890‘?’“!”(%)[#]{@}/\\&<-+÷×=>$€£¥¢:;,.*•°·…±†‡æ«»¦¯—–~˜¨_øÞ¿▬▭▮▯┐└╛░▒▓○‼⁇⁈⁉‽ℴℵℶℷℸℲ℮ℯ⅁⅂⅃⅄₠₡₢₣₤₥₦₧₨₩₪₫€₭₮₯₰₱₲₳₴₵₶₷₸₹₺₻₼₽₾₿ ",letterlike:"ABCDĐEFGHIJKLMNOPQRSTUVWXYZabcdđefghijklmnopqrstuvwxyzĄąĆ毿ŹźŃńóŁłАБВГҐДЂЕЁЄЖЗЅИІЇЙЈКЛЉМНЊОПРСТЋУЎФХЦЧЏШЩЪЫЬЭЮЯабвгґдђеёєжзѕиіїйјклљмнњопрстћуўфхцчџшщъыьэюяΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψωάΆέΈέΉίϊΐΊόΌύΰϋΎΫΏĂÂÊÔƠƯăâêôơưĂÂÊÔƠƯăâêôơư1234567890",numbers:"0123456789",zalgo:"̴̵̶̷̸̡̢̧̨̛̖̗̘̙̜̝̞̟̠̣̤̥̦̩̪̫̬̭̮̯̰̱̲̳̹̺̻̼͇͈͉͍͎̀́̂̃̄̅̆̇̈̉̊̋̌̍̎̏̐̑̒̓̔̽̾̿̀́͂̓̈́͆͊͋͌̕̚ͅ ͓͔͕͖͙͚͐͑͒͗͛ͣͤͥͦͧͨͩͪͫͬͭͮͯ͘͜͟͢͝͞͠͡͏҉",neo:"!<>-_\\/[]{}—=+*^?#________",uppercase:"1234567890QWERTYUIOPASDFGHJKLZXCVBNM#$%"},f={default:{steps:[1,8],interval:[60,170],delay:[0,2e3],changeChance:.6,ghostChance:.2,maxGhosts:.2,oneAtATime:0,glyphs:d.full+d.zalgo,glyphsFromText:!1,fillSpace:!0,mode:"matching",html:!1,letterize:!1,endless:!1,fps:60},nier:{maxGhosts:0,ghostChance:0,changeChance:.8,steps:3,interval:10,delay:0,oneAtATime:1,glyphs:d.nier,fillSpace:!1,glyphsFromText:!0,mode:"clear"},typewriter:{interval:[50,150],delay:0,steps:0,changeChance:0,maxGhosts:0,oneAtATime:1,glyphs:"",glyphsFromText:!1,fillSpace:!1,mode:"erase"},terminal:{interval:[25,30],delay:[0,0],steps:0,changeChance:.5,maxGhosts:0,oneAtATime:1,glyphs:"",fillSpace:!1,glyphsFromText:!1,mode:"clear"},zalgo:{delay:[0,3e3],interval:[10,35],steps:[0,30],maxGhosts:4.6,changeChance:.5,ghostChance:.7,glyphs:d.zalgo,glyphsFromText:!0,fillSpace:!1},neo:{interval:[30,100],delay:[0,1300],steps:[4,7],maxGhosts:0,ghostChance:0,changeChance:1,glyphs:d.neo,mode:"normal"},encrypted:{interval:[50,90],delay:[0,1300],steps:[5,8],maxGhosts:0,ghostChance:0,changeChance:1,glyphs:d.uppercase,fillSpace:!1,mode:"normal"},bitbybit:{interval:[35,65],delay:180,steps:1,maxGhosts:1,ghostChance:.1,changeChance:.7,oneAtATime:"word",glyphs:"",glyphsFromText:!0,fillSpace:!1,mode:"erase"},cosmic:{steps:[0,1],interval:30,delay:[400,2400],ghostChance:0,changeChance:.3,maxGhosts:0,glyphs:"QWERTYUIOPASDFGHJKLZXCVBNM",glyphsFromText:!1,fillSpace:!0,mode:"erase"}};class m{constructor(t,e){this.writer=t,this.set(e)}set(t){this.options=Object.assign(Object.assign({},f.default),this.parseOptions(t)),this.updateInternal()}extend(t){this.options=Object.assign(Object.assign({},this.options),this.parseOptions(t)),this.updateInternal()}parseOptions(t){var e;return t?"string"==typeof t?null!==(e=f[t])&&void 0!==e?e:{}:t:{}}updateInternal(){const{options:t}=this;this.glyphs=function(t){let e;return e="string"==typeof t?t:t.length?t.join(""):Array.from(t).join(""),e}(t.glyphs),this.setCharset(),this.space=t.fillSpace?" ":"",Number.isInteger(t.oneAtATime)?this.oneAtATime=t.oneAtATime:"word"===t.oneAtATime?this.oneAtATime="word":this.oneAtATime=t.oneAtATime?1:0}setCharset(){const{writer:t}=this;let{glyphs:e}=this;this.glyphsFromText&&(e+=function(t){const e="string"==typeof t,s=[];return new Set(t).forEach((t=>s.push(t))),e?s.join(""):s}(t.previousString+(this.html?g(t.goalText):t.goalText))),this.charset=[...e].filter((t=>!["\t","\n","\r","\f","\v"].includes(t))),this.setMaxGhosts()}setMaxGhosts(){const{writer:{charTable:t},options:{maxGhosts:e}}=this;Number.isInteger(e)&&(this.maxGhosts=e);const{length:s}=t.filter((t=>"tag"!==t.specialType));this.maxGhosts=Math.round((s||20)*e)}getGlyph(t){const{options:e}=this;return e.genGlyph?e.genGlyph(t,this.baseGetGlyph):this.baseGetGlyph()}baseGetGlyph(){var t,e;return null!==(t=(e=this.charset)[s(0,e.length,"floor")])&&void 0!==t?t:""}get steps(){return o(this.options.steps)}get interval(){return o(this.options.interval)}getDelay(t){const{options:e}=this;return e.genDelay?e.genDelay(t,this.baseGetDelay):this.baseGetDelay()}baseGetDelay(){return o(this.options.delay)}get mode(){return this.options.mode}get html(){return this.options.html}get endless(){return this.options.endless}get fps(){return this.options.fps}get letterize(){return this.options.letterize}get ghostChance(){return this.options.ghostChance}get changeChance(){return this.options.changeChance}get glyphsFromText(){return this.options.glyphsFromText}}class y{constructor(t){this.nGhosts=0,this.progress={percent:0,done:0,todo:0,increase(){this.done++,this.percent=this.done/this.todo},reset(t){this.percent=0,this.done=0,this.todo=t},finish(){this.done=this.todo,this.percent=1}},this.isTyping=!1,this.isPaused=!1,this.finished=!0,this.erasing=!1,this.writer=t,this.maxGhosts=this.writer.options.maxGhosts}get ghostsInLimit(){return this.nGhosts<this.maxGhosts}play(){this.isTyping=!0,this.isPaused=!1,this.finished=!1,this.toggleClass(!0),this.maxGhosts=this.writer.options.maxGhosts,this.writer.animator.run(),this.writer.emiter.callback("start",this.writer.goalText,this.writer.writerData)}pause(){this.isTyping=!1,this.isPaused=!0,this.toggleClass(!1)}finish(){this.progress.finish(),this.isTyping=!1,this.finished=!0,this.toggleClass(!1)}toggleClass(t){const e=this.writer.htmlElement,s="gw-writing";t?((t,e)=>{t.classList.remove(e),t.offsetWidth,t.classList.add(e)})(e,s):e.classList.remove(s)}}class v{constructor(t){this.callbacks={start:[],step:[],finish:[]},this.writer=t}addCallback(t,e){this.callbacks[t].push(e)}removeCallback(t,e){const s=this.callbacks[t],i=s.indexOf(e);return-1!==i&&(s.splice(i,1),!0)}callback(t,...e){this.callbacks[t].forEach((t=>t(...e)))}call(t){const{writer:e}=this;e.updateString();const{writerData:s,string:i}=e;if(e.options.letterize&&e.htmlElement.setAttribute("data-gw-string",e.options.html?g(i):i),"step"===t)return this.callback("step",i,s);e.state.finish(),e.state.erasing||(this.callback("finish",i,s),this.emitEvent())}emitEvent(){const{htmlElement:t,writerData:e}=this.writer;"undefined"!=typeof CustomEvent&&t.dispatchEvent(new CustomEvent("gw-finished",{detail:e}))}}var w=function(t,e,s,i){return new(s||(s=Promise))((function(n,r){function h(t){try{a(i.next(t))}catch(t){r(t)}}function o(t){try{a(i.throw(t))}catch(t){r(t)}}function a(t){var e;t.done?n(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(h,o)}a((i=i.apply(t,e||[])).next())}))};class T{constructor(t,e,s,i="",n,r){this.ghosts=[[],[]],this.stop=!1,this.afterGlitchChance=0,this.writer=t,this.setProps(e,s,i,n,r),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,n){const{options:r}=this.writer;this.index=n,this.l=t,this.gl=e,this.specialType=i,this.ghosts[0]=[...s],this.writer.state.nGhosts+=s.length,this.stepsLeft=r.steps,"tag"===i?this.stepsLeft=0:(t=>["\t","\n","\r","\f","\v",""," "].includes(t))(e)&&(this.specialType="whitespace"),this.afterGlitchChance=(r.ghostChance+r.changeChance)/3.7}reset(t,e,s="",i,n){this.setProps(t,e,s,i,n),this.els&&(this.els.letterEl.className="gw-letter")}get string(){const{l:t,ghosts:e}=this;return e[0].join("")+t+e[1].join("")}get finished(){const{l:t,gl:e,ghosts:s}=this;return t===e&&0===s[0].length&&0===s[1].length||"tag"===this.specialType}get interval(){let{interval:t}=this.writer.options;return"whitespace"===this.specialType&&(t/=1.8),t}writeToElement(){if(!this.els)return;const{ghostsBeforeEl:t,ghostsAfterEl:e,letterEl:s}=this.els;s.innerHTML=this.l,t.textContent=this.ghosts[0].join(""),e.textContent=this.ghosts[1].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 w(this,void 0,void 0,(function*(){const{writer:i}=this;return"tag"===this.specialType?(this.l=this.gl,i.emiter.call("step"),i.state.progress.increase(),!0):(yield n(i.options.getDelay(this)),yield r((()=>(!this.finished||i.options.endless)&&!i.state.isPaused&&!this.stop),(()=>w(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&&(i.state.progress.increase(),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||a(this.afterGlitchChance)&&"whitespace"!==this.specialType||s.options.endless){const{ghostChance:e,changeChance:i}=s.options;a(e)&&(s.state.ghostsInLimit?this.addGhost():this.removeGhost()),a(i)&&(null===(t=this.els)||void 0===t||t.letterEl.classList.add("gw-glitched"),this.l=s.options.getGlyph(this))}else this.finished||(null===(e=this.els)||void 0===e||e.letterEl.classList.remove("gw-glitched"),this.l=this.gl,this.removeGhost())}addGhost(){const{writer:t,ghosts:e}=this,s=t.options.getGlyph(this);t.state.nGhosts++,a()?x(e[0],s):x(e[1],s)}removeGhost(){const{writer:t,ghosts:e}=this;(a()&&e[0].length>0?i(e[0]):i(e[1]))&&t.state.nGhosts--}}function x(t,e){const{length:i}=t;t.splice(s(0,i,"floor"),0,e)}function E(){const t="clear"===this.options.mode&&this.state.finished?"":this.previousString;"matching"===this.options.mode?b.call(this,t):C.call(this,t)}function b(t){const e=Math.min(Math.ceil(this.options.maxGhosts/2),5),s=G.call(this,t);let i=-1;s.forEach(((s,n)=>{if(i++,"tag"===s.type)return i--,void A.call(this,n,"",s);const r=""!==s.value?t.indexOf(s.value,i):-1;if(-1!==r&&r-i<=e){const e=t.substring(i,r);A.call(this,n,s.value,s,e),i=r}else A.call(this,n,t[i],s)})),S(this.charTable,s.length)}function C(t){const e=G.call(this,t);let s=-1;e.forEach(((e,i)=>{if(s++,"tag"===e.type)return s--,void A.call(this,i,"",e);A.call(this,i,t[s],e)})),S(this.charTable,e.length)}function G(t){const{options:e,goalText:s}=this,i=e.html?function(t){const e=new RegExp(p,"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 a={value:i[0],type:void 0!==i[1]?"html_entity":"tag"};s.push(a)}return t.length>n&&s.push(...c(t.slice(n))),s}(s):c(s),n=Math.max(0,t.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)))}function A(t,e,s,i){const{charTable:n,options:r}=this,h=n[t];h?h.reset(null!=e?e:"",s.value||r.space,i,s.type,t):n.push(new T(this,null!=e?e:"",s.value||r.space,i,s.type,t))}function S(t,e){t.splice(e,t.length-e)}function P(){if(!this.options.letterize)return;const t=this.charTable.map((({specialType:t,gl:e})=>"tag"===t?e:'<span class="gw-char"></span>')).join("");this.htmlElement.innerHTML=t;const e=this.htmlElement.querySelectorAll("span.gw-char");let s=0;this.charTable.forEach((t=>{"tag"!==t.specialType&&(t.spanElement=e[s],s++)}))}var j=function(t,e,s,i){return new(s||(s=Promise))((function(n,r){function h(t){try{a(i.next(t))}catch(t){r(t)}}function o(t){try{a(i.throw(t))}catch(t){r(t)}}function a(t){var e;t.done?n(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(h,o)}a((i=i.apply(t,e||[])).next())}))};function M(t){const{charTable:e,state:s}=this,i=[];let n;n=e.filter(((t,e)=>"tag"!==t.specialType&&"html_entity"!==t.specialType&&(i.push(e),!0))).map((t=>t.gl)).join("").match(u);const h=[];{let t=-1,s=-1,r=-1;const o=()=>h[h.length-1];null==n||n.forEach((n=>{h.push([]),[...n].forEach((()=>{if(t++,s=i[t],r++,r!==s){for(let t=r;t<s;t++)o().push(e[t]);r=s}o().push(e[s])}))})),h.length||h.push([]);for(let t=s+1;t<e.length;t++)o().push(e[t])}h.reverse();let o=!0,a=!1;const l=()=>j(this,void 0,void 0,(function*(){var t;const e=h.pop();if(!e)return a=!0;const s=e.map((t=>t.type()));o=null!==(t=(yield Promise.all(s)).every((t=>t)))&&void 0!==t&&t}));t.push((()=>j(this,void 0,void 0,(function*(){return yield r((()=>!a&&o&&!s.isPaused),l),a&&o&&!s.isPaused})))())}var O=function(t,e,s,i){return new(s||(s=Promise))((function(n,r){function h(t){try{a(i.next(t))}catch(t){r(t)}}function o(t){try{a(i.throw(t))}catch(t){r(t)}}function a(t){var e;t.done?n(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(h,o)}a((i=i.apply(t,e||[])).next())}))};function D(t,e){var s;const{charTable:i,state:n,options:h}=this,o=null!==(s=null==e?void 0:e.reverse)&&void 0!==s&&s?[...i]:[...i].reverse(),a=()=>O(this,void 0,void 0,(function*(){let t=!0,e=!1;return yield r((()=>!e&&t&&!n.isPaused),(()=>O(this,void 0,void 0,(function*(){var s;const i=o.pop();i?t=null!==(s=yield i.type())&&void 0!==s&&s:e=!0})))),e&&t&&!n.isPaused}));for(let e=0;e<h.oneAtATime;e++)t.push(a())}class W{constructor(t){this.last=0,this.rate=16,this.running=!1,this.writer=t}run(){this.running||this.writer.options.letterize||(this.rate=Math.floor(1e3/this.writer.options.fps),this.running=!0,requestAnimationFrame(this.frame.bind(this)))}frame(t){return this.writer.state.isTyping?(this.last||(this.last=t),t-this.last<this.rate||(this.animate.call(this),this.last=t),requestAnimationFrame(this.frame.bind(this))):(this.animate.call(this),this.running=!1)}animate(){const{htmlElement:t,string:e}=this.writer;this.writer.options.html?t.innerHTML=e:t.textContent=e,t.setAttribute("data-gw-string",this.writer.options.html?g(e):e)}}var L=function(t,e,s,i){return new(s||(s=Promise))((function(n,r){function h(t){try{a(i.next(t))}catch(t){r(t)}}function o(t){try{a(i.throw(t))}catch(t){r(t)}}function a(t){var e;t.done?n(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(h,o)}a((i=i.apply(t,e||[])).next())}))};class R{constructor(t,e,s){var i;this.charTable=[],this.goalText="",this.lastText="",this.string="",this.htmlElement=t?"string"==typeof t?null!==(i=document.querySelector(t))&&void 0!==i?i:document.createElement("span"):t:document.createElement("span"),this.htmlElement.$writer=this,this.options=new m(this,e),this.state=new y(this),this.emiter=new v(this),s&&this.emiter.addCallback("finish",s),this.animator=new W(this),this.string=this.previousString}updateString(){this.string=this.charTable.map((t=>t.string)).join("")}get previousString(){let t=this.htmlElement.textContent;return"string"!=typeof t&&(t=this.options.html?g(this.string):this.string),t=t.trim(),t}get writerData(){const{options:t,state:e,string:s}=this;return{string:s,writer:this,options:t,state:e}}write(t){return L(this,void 0,void 0,(function*(){return this.manageWriting(t)}))}add(t){return L(this,void 0,void 0,(function*(){const{previousString:e}=this;return this.write(e+t)}))}remove(t){return L(this,void 0,void 0,(function*(){const{previousString:e}=this,s=Array.from(e);return s.splice(-t),this.write(s.join(""))}))}endless(t){this.options.extend({endless:t})}addCallback(t,e){this.emiter.addCallback(t,e)}removeCallback(t,e){this.emiter.removeCallback(t,e)}play(){return L(this,void 0,void 0,(function*(){return this.manageWriting(null)}))}pause(){this.state.pause()}manageWriting(t){return L(this,void 0,void 0,(function*(){if(null!==t&&(this.lastText=t),"erase"===this.options.mode&&(this.state.finished||this.state.erasing)){this.state.erasing=!0;const t=this.genGoalStringToErase(this.lastText);if(this.preparePropertiesBeforeWrite(t),yield this.playChT({reverse:0!==this.options.oneAtATime}),!this.state.finished)return this.getWriterData("ERROR","Erasing did not finish.");this.state.erasing=!1}return this.preparePropertiesBeforeWrite(this.lastText),this.pause(),this.playChT()}))}preparePropertiesBeforeWrite(t){this.goalText=t,this.state.nGhosts=0,this.options.setCharset(),E.call(this),this.state.progress.reset(this.charTable.length),P.call(this)}playChT(t){return L(this,void 0,void 0,(function*(){const e=[],{charTable:s,state:i,options:n}=this;if(i.isTyping)return this.getWriterData("ERROR","The writer is already typing.");i.play(),n.oneAtATime>0?D.call(this,e,t):"word"===n.oneAtATime?M.call(this,e):s.forEach((t=>e.push(t.type())));try{const t=(yield Promise.all(e)).every((t=>t));return this.returnResult(t)}catch(t){return this.getWriterData("ERROR","Writer encountered an error.",t)}}))}returnResult(t){return t?this.emiter.call("finish"):this.emiter.call("step"),t?this.getWriterData("SUCCESS","The writer finished typing."):this.getWriterData("ERROR","Writer failed to finish typing.")}getWriterData(t,e,s){const{writerData:i}=this;return Object.assign(Object.assign({},i),{status:t,message:e,error:s})}genGoalStringToErase(t){var e;const{previousString:s}=this;let i="";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 k(t,e,s,i){return L(this,void 0,void 0,(function*(){return new R(e,s,i).write(t)}))}const F=(t,e,s)=>new R(t,e,s);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.GlitchedWriter=e():t.GlitchedWriter=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,{create:()=>F,default:()=>k,glitchWrite:()=>q,glyphs:()=>d,presets:()=>f,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 a=(t=.5)=>Math.random()<t,l=t=>({value:t}),c=t=>[...t].map(l),p="(&(?:[a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});)|(<style.+?>.+?</style>|<script.+?>.+?<\/script>|<(?:!|/?[a-zA-Z]+).*?/?>)",u=/(&(?:[a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});)|.\w+,*\.*"*\s?|\s+|\S+/gi;function g(t){const e=new RegExp(p,"g");return t.replace(e,"")}const d={nier:"一二三四五六七八九十百千上下左右中大小月日年早木林山川土空田天生花草虫犬人名女男子目耳口手足見音力気円入出立休先夕本文字学校村町森正水火玉王石竹糸貝車金雨赤青白数多少万半形太細広長点丸交光角計直線矢弱強高同親母父姉兄弟妹自友体毛頭顔首心時曜朝昼夜分週春夏秋冬今新古間方北南東西遠近前後内外場地国園谷野原里市京風雪雲池海岩星室戸家寺通門道話言答声聞語読書記紙画絵図工教晴思考知才理算作元食肉馬牛魚鳥羽鳴麦米茶色黄黒来行帰歩走止活店買売午汽弓回会組船明社切電毎合当台楽公引科歌刀番用何",full:"ABCDĐEFGHIJKLMNOPQRSTUVWXYZabcdđefghijklmnopqrstuvwxyzĄąĆ毿ŹźŃńóŁłАБВГҐДЂЕЁЄЖЗЅИІЇЙЈКЛЉМНЊОПРСТЋУЎФХЦЧЏШЩЪЫЬЭЮЯабвгґдђеёєжзѕиіїйјклљмнњопрстћуўфхцчџшщъыьэюяΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψωάΆέΈέΉίϊΐΊόΌύΰϋΎΫΏĂÂÊÔƠƯăâêôơư一二三四五六七八九十百千上下左右中大小月日年早木林山川土空田天生花草虫犬人名女男子目耳口手足見音力気円入出立休先夕本文字学校村町森正水火玉王石竹糸貝車金雨赤青白数多少万半形太細広長点丸交光角計直線矢弱強高同親母父姉兄弟妹自友体毛頭顔首心時曜朝昼夜分週春夏秋冬今新古間方北南東西遠近前後内外場地国園谷野原里市京風雪雲池海岩星室戸家寺通門道話言答声聞語読書記紙画絵図工教晴思考知才理算作元食肉馬牛魚鳥羽鳴麦米茶色黄黒来行帰歩走止活店買売午汽弓回会組船明社切電毎合当台楽公引科歌刀番用何ĂÂÊÔƠƯăâêôơư1234567890‘?’“!”(%)[#]{@}/\\&<-+÷×=>$€£¥¢:;,.*•°·…±†‡æ«»¦¯—–~˜¨_øÞ¿▬▭▮▯┐└╛░▒▓○‼⁇⁈⁉‽ℴℵℶℷℸℲ℮ℯ⅁⅂⅃⅄₠₡₢₣₤₥₦₧₨₩₪₫€₭₮₯₰₱₲₳₴₵₶₷₸₹₺₻₼₽₾₿ ",letterlike:"ABCDĐEFGHIJKLMNOPQRSTUVWXYZabcdđefghijklmnopqrstuvwxyzĄąĆ毿ŹźŃńóŁłАБВГҐДЂЕЁЄЖЗЅИІЇЙЈКЛЉМНЊОПРСТЋУЎФХЦЧЏШЩЪЫЬЭЮЯабвгґдђеёєжзѕиіїйјклљмнњопрстћуўфхцчџшщъыьэюяΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψωάΆέΈέΉίϊΐΊόΌύΰϋΎΫΏĂÂÊÔƠƯăâêôơưĂÂÊÔƠƯăâêôơư1234567890",numbers:"0123456789",zalgo:"̴̵̶̷̸̡̢̧̨̛̖̗̘̙̜̝̞̟̠̣̤̥̦̩̪̫̬̭̮̯̰̱̲̳̹̺̻̼͇͈͉͍͎̀́̂̃̄̅̆̇̈̉̊̋̌̍̎̏̐̑̒̓̔̽̾̿̀́͂̓̈́͆͊͋͌̕̚ͅ ͓͔͕͖͙͚͐͑͒͗͛ͣͤͥͦͧͨͩͪͫͬͭͮͯ͘͜͟͢͝͞͠͡͏҉",neo:"!<>-_\\/[]{}—=+*^?#________",uppercase:"1234567890QWERTYUIOPASDFGHJKLZXCVBNM#$%"},f={default:{steps:[1,8],interval:[60,170],delay:[0,2e3],changeChance:.6,ghostChance:.2,maxGhosts:.2,oneAtATime:0,glyphs:d.full+d.zalgo,glyphsFromText:!1,fillSpace:!0,mode:"matching",html:!1,letterize:!1,endless:!1,fps:60},nier:{maxGhosts:0,ghostChance:0,changeChance:.8,steps:3,interval:10,delay:0,oneAtATime:1,glyphs:d.nier,fillSpace:!1,glyphsFromText:!0,mode:"clear"},typewriter:{interval:[50,150],delay:0,steps:0,changeChance:0,maxGhosts:0,oneAtATime:1,glyphs:"",glyphsFromText:!1,fillSpace:!1,mode:"erase_smart"},terminal:{interval:[25,30],delay:[0,0],steps:0,changeChance:.5,maxGhosts:0,oneAtATime:1,glyphs:"",fillSpace:!1,glyphsFromText:!1,mode:"clear"},zalgo:{delay:[0,3e3],interval:[10,35],steps:[0,30],maxGhosts:4.6,changeChance:.5,ghostChance:.7,glyphs:d.zalgo,glyphsFromText:!0,fillSpace:!1},neo:{interval:[30,100],delay:[0,1300],steps:[4,7],maxGhosts:0,ghostChance:0,changeChance:1,glyphs:d.neo,mode:"normal"},encrypted:{interval:[50,90],delay:[0,1300],steps:[5,8],maxGhosts:0,ghostChance:0,changeChance:1,glyphs:d.uppercase,fillSpace:!1,mode:"normal"},bitbybit:{interval:[35,65],delay:180,steps:1,maxGhosts:1,ghostChance:.1,changeChance:.7,oneAtATime:"word",glyphs:"",glyphsFromText:!0,fillSpace:!1,mode:"erase"},cosmic:{steps:[0,1],interval:30,delay:[400,2400],ghostChance:0,changeChance:.3,maxGhosts:0,glyphs:"QWERTYUIOPASDFGHJKLZXCVBNM",glyphsFromText:!1,fillSpace:!0,mode:"erase"}};class m{constructor(t,e){this.writer=t,this.set(e)}set(t){this.options=Object.assign(Object.assign({},f.default),this.parseOptions(t)),this.updateInternal()}extend(t){this.options=Object.assign(Object.assign({},this.options),this.parseOptions(t)),this.updateInternal()}parseOptions(t){var e;return t?"string"==typeof t?null!==(e=f[t])&&void 0!==e?e:{}:t:{}}updateInternal(){const{options:t}=this;this.glyphs=function(t){let e;return e="string"==typeof t?t:t.length?t.join(""):Array.from(t).join(""),e}(t.glyphs),this.setCharset(),this.space=t.fillSpace?" ":"",Number.isInteger(t.oneAtATime)?this.oneAtATime=t.oneAtATime:"word"===t.oneAtATime?this.oneAtATime="word":this.oneAtATime=t.oneAtATime?1:0}setCharset(){const{writer:t}=this;let{glyphs:e}=this;this.glyphsFromText&&(e+=function(t){const e="string"==typeof t,s=[];return new Set(t).forEach((t=>s.push(t))),e?s.join(""):s}(t.previousString+(this.html?g(t.goalText):t.goalText))),this.charset=[...e].filter((t=>!["\t","\n","\r","\f","\v"].includes(t))),this.setMaxGhosts()}setMaxGhosts(){const{writer:{charTable:t},options:{maxGhosts:e}}=this;Number.isInteger(e)&&(this.maxGhosts=e);const{length:s}=t.filter((t=>"tag"!==t.specialType));this.maxGhosts=Math.round((s||20)*e)}getGlyph(t){const{options:e}=this;return e.genGlyph?e.genGlyph(t,this.baseGetGlyph):this.baseGetGlyph()}baseGetGlyph(){var t,e;return null!==(t=(e=this.charset)[s(0,e.length,"floor")])&&void 0!==t?t:""}get steps(){return o(this.options.steps)}get interval(){return o(this.options.interval)}getDelay(t){const{options:e}=this;return e.genDelay?e.genDelay(t,this.baseGetDelay):this.baseGetDelay()}baseGetDelay(){return o(this.options.delay)}get mode(){return this.options.mode}get html(){return this.options.html}get endless(){return this.options.endless}get fps(){return this.options.fps}get letterize(){return this.options.letterize}get ghostChance(){return this.options.ghostChance}get changeChance(){return this.options.changeChance}get glyphsFromText(){return this.options.glyphsFromText}}class y{constructor(t){this.nGhosts=0,this.progress={percent:0,done:0,todo:0,increase(){this.done++,this.percent=this.done/this.todo},reset(t){this.percent=0,this.done=0,this.todo=t},finish(){this.done=this.todo,this.percent=1}},this.isTyping=!1,this.isPaused=!1,this.finished=!0,this.erasing=!1,this.writer=t,this.maxGhosts=this.writer.options.maxGhosts}get ghostsInLimit(){return this.nGhosts<this.maxGhosts}play(){this.isTyping=!0,this.isPaused=!1,this.finished=!1,this.toggleClass(!0),this.maxGhosts=this.writer.options.maxGhosts,this.writer.animator.run(),this.writer.emiter.callback("start",this.writer.goalText,this.writer.writerData)}pause(){this.isTyping=!1,this.isPaused=!0,this.toggleClass(!1)}finish(){this.progress.finish(),this.isTyping=!1,this.finished=!0,this.toggleClass(!1)}toggleClass(t){const e=this.writer.htmlElement,s="gw-writing";t?((t,e)=>{t.classList.remove(e),t.offsetWidth,t.classList.add(e)})(e,s):e.classList.remove(s)}}class v{constructor(t){this.callbacks={start:[],step:[],finish:[]},this.writer=t}addCallback(t,e){this.callbacks[t].push(e)}removeCallback(t,e){const s=this.callbacks[t],i=s.indexOf(e);return-1!==i&&(s.splice(i,1),!0)}callback(t,...e){this.callbacks[t].forEach((t=>t(...e)))}call(t){const{writer:e}=this;e.updateString();const{writerData:s,string:i}=e;if(e.options.letterize&&e.htmlElement.setAttribute("data-gw-string",e.options.html?g(i):i),"step"===t)return this.callback("step",i,s);e.state.finish(),e.state.erasing||(this.callback("finish",i,s),this.emitEvent())}emitEvent(){const{htmlElement:t,writerData:e}=this.writer;"undefined"!=typeof CustomEvent&&t.dispatchEvent(new CustomEvent("gw-finished",{detail:e}))}}var w=function(t,e,s,i){return new(s||(s=Promise))((function(n,r){function h(t){try{a(i.next(t))}catch(t){r(t)}}function o(t){try{a(i.throw(t))}catch(t){r(t)}}function a(t){var e;t.done?n(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(h,o)}a((i=i.apply(t,e||[])).next())}))};class T{constructor(t,e,s,i="",n,r){this.ghosts=[[],[]],this.stop=!1,this.afterGlitchChance=0,this.writer=t;const{options:h}=t;this.index=r,this.l=e,this.gl=s,this.specialType=n,this.ghosts[0]=[...i],this.writer.state.nGhosts+=i.length,this.stepsLeft=h.steps,"tag"===n?this.stepsLeft=0:(t=>["\t","\n","\r","\f","\v",""," "].includes(t))(s)&&(this.specialType="whitespace"),this.afterGlitchChance=(h.ghostChance+h.changeChance)/3.7,t.options.letterize&&(this.els={ghostsBeforeEl:document.createElement("span"),letterEl:document.createElement("span"),ghostsAfterEl:document.createElement("span")},this.els.ghostsBeforeEl.className="gw-ghosts",this.els.ghostsAfterEl.className="gw-ghosts",this.els.letterEl.className="gw-letter")}get string(){const{l:t,ghosts:e}=this;return e[0].join("")+t+e[1].join("")}get finished(){const{l:t,gl:e,ghosts:s}=this;return t===e&&0===s[0].length&&0===s[1].length||"tag"===this.specialType}get interval(){let{interval:t}=this.writer.options;return"whitespace"===this.specialType&&(t/=1.8),t}writeToElement(){if(!this.els)return;const{ghostsBeforeEl:t,ghostsAfterEl:e,letterEl:s}=this.els;s.innerHTML=this.l,t.textContent=this.ghosts[0].join(""),e.textContent=this.ghosts[1].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 w(this,void 0,void 0,(function*(){const{writer:i}=this;return"tag"===this.specialType?(this.l=this.gl,i.emiter.call("step"),i.state.progress.increase(),!0):(yield n(i.options.getDelay(this)),yield r((()=>(!this.finished||i.options.endless)&&!i.state.isPaused&&!this.stop),(()=>w(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&&(i.state.progress.increase(),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||a(this.afterGlitchChance)&&"whitespace"!==this.specialType||s.options.endless){const{ghostChance:e,changeChance:i}=s.options;a(e)&&(s.state.ghostsInLimit?this.addGhost():this.removeGhost()),a(i)&&(null===(t=this.els)||void 0===t||t.letterEl.classList.add("gw-glitched"),this.l=s.options.getGlyph(this))}else this.finished||(null===(e=this.els)||void 0===e||e.letterEl.classList.remove("gw-glitched"),this.l=this.gl,this.removeGhost())}addGhost(){const{writer:t,ghosts:e}=this,s=t.options.getGlyph(this);t.state.nGhosts++,a()?x(e[0],s):x(e[1],s)}removeGhost(){const{writer:t,ghosts:e}=this;(a()&&e[0].length>0?i(e[0]):i(e[1]))&&t.state.nGhosts--}}function x(t,e){const{length:i}=t;t.splice(s(0,i,"floor"),0,e)}function b(){const{charTable:t,options:e}=this,s="clear"===e.mode&&this.state.finished?"":this.previousString;t.forEach((t=>t.stop=!0)),this.charTable=[],"matching"===e.mode?E.call(this,s):C.call(this,s)}function E(t){const e=Math.min(Math.ceil(this.options.maxGhosts/2),5),s=G.call(this,t);let i=-1;s.forEach(((s,n)=>{if(i++,"tag"===s.type)return i--,void A.call(this,n,"",s);const r=""!==s.value?t.indexOf(s.value,i):-1;if(-1!==r&&r-i<=e){const e=t.substring(i,r);A.call(this,n,s.value,s,e),i=r}else A.call(this,n,t[i],s)})),S(this.charTable,s.length)}function C(t){const e=G.call(this,t);let s=-1;e.forEach(((e,i)=>{if(s++,"tag"===e.type)return s--,void A.call(this,i,"",e);A.call(this,i,t[s],e)})),S(this.charTable,e.length)}function G(t){const{options:e,goalText:s}=this,i=e.html?function(t){const e=new RegExp(p,"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 a={value:i[0],type:void 0!==i[1]?"html_entity":"tag"};s.push(a)}return t.length>n&&s.push(...c(t.slice(n))),s}(s):c(s),n=Math.max(0,t.length-i.length);if(e.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)))}function A(t,e,s,i){const{charTable:n,options:r}=this;n.push(new T(this,null!=e?e:"",s.value||r.space,i,s.type,t))}function S(t,e){t.splice(e,t.length-e)}function P(){if(!this.options.letterize)return;const t=this.charTable.map((({specialType:t,gl:e})=>"tag"===t?e:'<span class="gw-char"></span>')).join("");this.htmlElement.innerHTML=t;const e=this.htmlElement.querySelectorAll("span.gw-char");let s=0;this.charTable.forEach((t=>{"tag"!==t.specialType&&(t.spanElement=e[s],s++)}))}var W=function(t,e,s,i){return new(s||(s=Promise))((function(n,r){function h(t){try{a(i.next(t))}catch(t){r(t)}}function o(t){try{a(i.throw(t))}catch(t){r(t)}}function a(t){var e;t.done?n(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(h,o)}a((i=i.apply(t,e||[])).next())}))};function j(t){const{charTable:e,state:s}=this,i=[];let n;n=e.filter(((t,e)=>"tag"!==t.specialType&&"html_entity"!==t.specialType&&(i.push(e),!0))).map((t=>t.gl)).join("").match(u);const h=[];{let t=-1,s=-1,r=-1;const o=()=>h[h.length-1];null==n||n.forEach((n=>{h.push([]),[...n].forEach((()=>{if(t++,s=i[t],r++,r!==s){for(let t=r;t<s;t++)o().push(e[t]);r=s}o().push(e[s])}))})),h.length||h.push([]);for(let t=s+1;t<e.length;t++)o().push(e[t])}h.reverse();let o=!0,a=!1;const l=()=>W(this,void 0,void 0,(function*(){var t;const e=h.pop();if(!e)return a=!0;const s=e.map((t=>t.type()));o=null!==(t=(yield Promise.all(s)).every((t=>t)))&&void 0!==t&&t}));t.push((()=>W(this,void 0,void 0,(function*(){return yield r((()=>!a&&o&&!s.isPaused),l),a&&o&&!s.isPaused})))())}var D=function(t,e,s,i){return new(s||(s=Promise))((function(n,r){function h(t){try{a(i.next(t))}catch(t){r(t)}}function o(t){try{a(i.throw(t))}catch(t){r(t)}}function a(t){var e;t.done?n(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(h,o)}a((i=i.apply(t,e||[])).next())}))};function L(t,e){var s;const{charTable:i,state:n,options:h}=this,o=null!==(s=null==e?void 0:e.reverse)&&void 0!==s&&s?[...i]:[...i].reverse(),a=()=>D(this,void 0,void 0,(function*(){let t=!0,e=!1;return yield r((()=>!e&&t&&!n.isPaused),(()=>D(this,void 0,void 0,(function*(){var s;const i=o.pop();i?t=null!==(s=yield i.type())&&void 0!==s&&s:e=!0})))),e&&t&&!n.isPaused}));for(let e=0;e<h.oneAtATime;e++)t.push(a())}class M{constructor(t){this.last=0,this.rate=16,this.running=!1,this.writer=t}run(){this.running||this.writer.options.letterize||(this.rate=Math.floor(1e3/this.writer.options.fps),this.running=!0,requestAnimationFrame(this.frame.bind(this)))}frame(t){return this.writer.state.isTyping?(this.last||(this.last=t),t-this.last<this.rate||(this.animate.call(this),this.last=t),requestAnimationFrame(this.frame.bind(this))):(this.animate.call(this),this.running=!1)}animate(){const{htmlElement:t,string:e}=this.writer;this.writer.options.html?t.innerHTML=e:t.textContent=e,t.setAttribute("data-gw-string",this.writer.options.html?g(e):e)}}class O{constructor(t,e,s=800,i=!1){if(this.isStopped=!1,this.isLooping=!1,this.loopInterval=0,this.index=-1,this.writer=t,this.interval=s,Array.isArray(e))this.texts=e;else{let t;t="object"==typeof e?e:document.querySelector(e),this.texts=[],null==t||t.childNodes.forEach((t=>{const{tagName:e,innerHTML:s}=t;"P"===e&&void 0!==s&&this.texts.push(s)}))}"boolean"==typeof i?this.isLooping=i:"function"==typeof i?this.endCallback=i:(this.isLooping=!0,this.loopInterval=i),this.loop()}stop(){this.isStopped=!0}resume(){this.index--,this.isStopped=!1,this.writer.state.isPaused=!1,this.loop()}loop(){var t,e,s,i,r;return e=this,s=void 0,r=function*(){if(this.texts.length){if(this.index++,this.index>=this.texts.length){if(!this.isLooping)return null===(t=this.endCallback)||void 0===t?void 0:t.call(this,this.writer.string,this.writer.getWriterData("SUCCESS","The queue has reached it's end."));yield n(this.loopInterval),this.index=0}this.isStopped||this.writer.state.isPaused||(yield this.writer.manageWriting(this.texts[this.index]))&&!this.writer.state.isPaused&&(yield n(this.interval),this.loop())}},new((i=void 0)||(i=Promise))((function(t,n){function h(t){try{a(r.next(t))}catch(t){n(t)}}function o(t){try{a(r.throw(t))}catch(t){n(t)}}function a(e){var s;e.done?t(e.value):(s=e.value,s instanceof i?s:new i((function(t){t(s)}))).then(h,o)}a((r=r.apply(e,s||[])).next())}))}}var R=function(t,e,s,i){return new(s||(s=Promise))((function(n,r){function h(t){try{a(i.next(t))}catch(t){r(t)}}function o(t){try{a(i.throw(t))}catch(t){r(t)}}function a(t){var e;t.done?n(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(h,o)}a((i=i.apply(t,e||[])).next())}))};class k{constructor(t,e,s){var i;this.charTable=[],this.goalText="",this.lastText="",this.string="",this.htmlElement=t?"string"==typeof t?null!==(i=document.querySelector(t))&&void 0!==i?i:document.createElement("span"):t:document.createElement("span"),this.htmlElement.$writer=this,this.options=new m(this,e),this.state=new y(this),this.emiter=new v(this),s&&this.emiter.addCallback("finish",s),this.animator=new M(this),this.string=this.previousString}updateString(){this.string=this.charTable.map((t=>t.string)).join("")}get previousString(){let t=this.htmlElement.textContent;return"string"!=typeof t&&(t=this.options.html?g(this.string):this.string),t=t.trim(),t}get writerData(){const{options:t,state:e,string:s}=this;return{string:s,writer:this,options:t,state:e}}write(t,e,s){return R(this,void 0,void 0,(function*(){if(this.queue&&(this.queue.stop(),delete this.queue),"string"==typeof t)return this.manageWriting(t);this.queryWrite(t,e,s)}))}queryWrite(t,e,s){this.queue&&(this.queue.stop(),delete this.queue),this.queue=new O(this,t,e,s)}add(t){return R(this,void 0,void 0,(function*(){const{previousString:e}=this;return this.write(e+t)}))}remove(t){return R(this,void 0,void 0,(function*(){const{previousString:e}=this,s=Array.from(e);return s.splice(-t),this.write(s.join(""))}))}play(){return R(this,void 0,void 0,(function*(){return this.state.isPaused?this.queue?(this.queue.resume(),this.getWriterData("SUCCESS","The queue was resumed")):this.manageWriting(null):this.getWriterData("ERROR","The writer isn't paused.")}))}pause(){this.state.pause()}endless(t){this.options.extend({endless:t})}addCallback(t,e){this.emiter.addCallback(t,e)}removeCallback(t,e){this.emiter.removeCallback(t,e)}manageWriting(t){return R(this,void 0,void 0,(function*(){if(null!==t&&(this.lastText=t),["erase_smart","erase"].includes(this.options.mode)&&(this.state.finished||this.state.erasing)){this.state.erasing=!0;const t=this.genGoalStringToErase(this.lastText);if(this.preparePropertiesBeforeWrite(t),yield this.playChT({reverse:0!==this.options.oneAtATime}),!this.state.finished)return this.getWriterData("ERROR","Erasing did not finish.");this.state.erasing=!1}return this.preparePropertiesBeforeWrite(this.lastText),this.pause(),this.playChT()}))}preparePropertiesBeforeWrite(t){this.goalText=t,this.state.nGhosts=0,this.options.setCharset(),b.call(this),this.state.progress.reset(this.charTable.length),P.call(this)}playChT(t){return R(this,void 0,void 0,(function*(){const e=[],{charTable:s,state:i,options:n}=this;if(i.isTyping)return this.getWriterData("ERROR","The writer is already typing.");i.play(),n.oneAtATime>0?L.call(this,e,t):"word"===n.oneAtATime?j.call(this,e):s.forEach((t=>e.push(t.type())));try{const t=(yield Promise.all(e)).every((t=>t));return this.returnResult(t)}catch(t){return this.getWriterData("ERROR","Writer encountered an error.",t)}}))}returnResult(t){return t?this.emiter.call("finish"):this.emiter.call("step"),t?this.getWriterData("SUCCESS","The writer finished typing."):this.getWriterData("ERROR","Writer failed to finish typing.")}getWriterData(t,e,s){const{writerData:i}=this;return Object.assign(Object.assign({},i),{status:t,message:e,error:s})}genGoalStringToErase(t){var e;const{previousString:s}=this;let i="";if("erase_smart"===this.options.mode)for(let n=0;n<t.length;n++){const r=t[n],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 q(t,e,s,i,n){return R(this,void 0,void 0,(function*(){const r=new k(e,s,n);return i&&r.addCallback("step",i),r.write(t)}))}const F=(t,e,s)=>new k(t,e,s);return e})()})); | ||
//# sourceMappingURL=index.min.map |
{ | ||
"name": "glitched-writer", | ||
"version": "2.0.27", | ||
"version": "2.0.28", | ||
"description": "Glitched, text writing module. Highly customizable settings. Decoding, decrypting, scrambling, or simply spelling out text.", | ||
@@ -25,3 +25,2 @@ "author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>", | ||
"scripts": { | ||
"start": "nodemon test/index.ts", | ||
"dev": "parcel dev/index.html --dist-dir dev/dist", | ||
@@ -44,6 +43,4 @@ "build": "tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && grunt build", | ||
"grunt-webpack": "^4.0.3", | ||
"jsdom": "^16.5.3", | ||
"load-grunt-tasks": "^5.1.0", | ||
"lodash.debounce": "^4.0.8", | ||
"nodemon": "^2.0.7", | ||
"parcel": "^2.0.0-beta.2", | ||
@@ -50,0 +47,0 @@ "terser-webpack-plugin": "^5.1.2", |
# Glitched Writer | ||
[![npm](https://img.shields.io/npm/v/glitched-writer)](https://www.npmjs.com/package/glitched-writer) [![npm type definitions](https://img.shields.io/npm/types/glitched-writer)](https://www.npmjs.com/package/glitched-writer) [![](https://data.jsdelivr.com/v1/package/npm/glitched-writer/badge?style=rounded)](https://www.jsdelivr.com/package/npm/glitched-writer) [![NPM](https://img.shields.io/npm/l/glitched-writer)](https://www.npmjs.com/package/glitched-writer) | ||
[![npm](https://img.shields.io/npm/v/glitched-writer)](https://www.npmjs.com/package/glitched-writer) | ||
[![npm type definitions](https://img.shields.io/npm/types/glitched-writer)](https://www.npmjs.com/package/glitched-writer) | ||
[![](https://data.jsdelivr.com/v1/package/npm/glitched-writer/badge?style=rounded)](https://www.jsdelivr.com/package/npm/glitched-writer) | ||
[![bundle size](https://img.shields.io/bundlephobia/minzip/glitched-writer)](https://bundlephobia.com/result?p=glitched-writer) | ||
[![npm](https://img.shields.io/npm/dt/glitched-writer)](https://www.npmjs.com/package/glitched-writer) | ||
@@ -42,2 +45,4 @@ | ||
- [Writing](#writing) | ||
- [Queue Writing](#queue-writing) | ||
- [Texts from HTML](<#texts-from-html-(seo-friendly)>) | ||
- [Pausing & Playing](#pausing--playing) | ||
@@ -92,3 +97,3 @@ - [One-Time-Use](#one-time-use) | ||
// use create method to create new instance. | ||
const writer = GlitchedWriter.create(Element, options, stepCB, finishCB) | ||
const writer = GlitchedWriter.create(Element, options, finishCB) | ||
``` | ||
@@ -143,4 +148,47 @@ | ||
### Queue Writing | ||
If you have prepared array of texts to write - in a loop, or one time - you can pass them all to the .write() method and initiate a Queue. | ||
```js | ||
const phrases = ['First, write this.', 'Then this.', 'And finally this!'] | ||
writer.write(phrases, 1000, true) | ||
/** | ||
* 1. @param texts - Array of strings to write | ||
* 2. @param queueInterval - Time to wait between writing each texts [ms] | ||
* 3. @param loop - boolean | Callback | number - What to do when the queue has ended. | ||
* - false -> stop; | ||
* - true -> continue looping; | ||
* - Callback -> stop and fire the callback. | ||
* - number -> wait number ms and than continue | ||
*/ | ||
``` | ||
### Texts from HTML (SEO Friendly) | ||
Instead of using the `string` array, you can place an `div` with your queue as `paragraphs` on the page. Then pass it to the queueWrite function as first param. | ||
This allows bots and search engines, as well as users with JavaScript disabled, to see your text on the page. | ||
```html | ||
<div id="phrases" style="display: none;"> | ||
<p>Welcome!</p> | ||
<p>to my <b>awesome</b> website.</p> | ||
</div> | ||
``` | ||
```js | ||
writer.queueWrite('#phrases', queueInterval, loop) | ||
/** | ||
* @param texts | ||
* - string[] - Array of strings to write | ||
* - html element - the parent element with the paragraphs | ||
* - string - query selector pointing to that element | ||
``` | ||
### Pausing & Playing | ||
You can pause and resume playing at any time. | ||
```js | ||
@@ -152,10 +200,10 @@ Writer.write('Some very cool header.').then(({ status, message }) => { | ||
setTimeout(() => { | ||
Writer.pause() // will stop writing | ||
}, 1000) | ||
setTimeout( | ||
() => Writer.pause(), // will stop writing | ||
1000, | ||
) | ||
setTimeout(async () => { | ||
await Writer.play() // continue writing | ||
console.log(Writer.string) // will log after finished writing | ||
const { string } = await Writer.play() // continue writing | ||
console.log('Completed:', string) // will log after finished writing | ||
}, 2000) | ||
@@ -171,3 +219,3 @@ ``` | ||
glitchWrite('Write this and DISAPER!', htmlElement, options, ...) | ||
glitchWrite('Write this and DISAPER!', htmlElement, options, stepCB, finishCB) | ||
``` | ||
@@ -178,8 +226,10 @@ | ||
Don't be afraid to call write method on top of each oder. | ||
New will stop the ongoing. | ||
New will stop the ongoing. But, it's good to `debounce` the event handler. | ||
```js | ||
inputEl.addEventListener('input', () => { | ||
Writer.write(inputEl.value) | ||
}) | ||
import debounce from 'lodash.debounce' | ||
const onInput = debounce(() => writer.write(inputEl.value), 500) | ||
inputEl.addEventListener('input', onInput) | ||
``` | ||
@@ -211,3 +261,3 @@ | ||
.add(string) & .remove(number) are methods usefull for quick changes to the displayed text. | ||
`.add(string)` & `.remove(number)` are methods usefull for quick changes to the displayed text. | ||
@@ -237,3 +287,3 @@ ```js | ||
Splits written text into series of span elements. Then writing letters seperately into these child-elements. | ||
Splits written text into series of `<span>` elements. Then writing letters seperately into these child-elements. | ||
@@ -256,3 +306,3 @@ ```js | ||
Option "endless" let's you run the text animation until you disable that function. | ||
Option `endless` let's you run the text animation until you disable that function. | ||
@@ -327,3 +377,3 @@ This opens the door for some additional effects, like: **Show on hover** (e.g. on secret fields) or **refreshing text** to give it user attention. | ||
List of all things that can be imported from glitched-writer module. | ||
List of all things that can be imported from `glitched-writer` module. | ||
@@ -447,2 +497,3 @@ ```ts | ||
- 'erase' - _First Erases entire string and then writes your text._ | ||
- 'erase*smart' - Same as erase, but saves the matching begginging letters* | ||
- 'clear' - _Instantly deletes entire textContent and then writes your text._ | ||
@@ -491,1 +542,9 @@ | ||
``` | ||
## The End - couple of final words | ||
Thanks for checking out the Glitched Writer. Let me know, if you are using it somewhere - would love to see it working out there. | ||
If you have any questions, just create new [discusion](https://github.com/thetarnav/glitched-writer/discussions) or [issue](https://github.com/thetarnav/glitched-writer/issues). Or just send me an email at gthetarnav@gmail.com, if you want. | ||
Presets or feature ideas are also welcome :) |
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
272364
18
59
3733
539