UNPKG

glitched-writer

Version:

Glitched, text writing module. Highly customizable settings. Decoding, decrypting, scrambling, or simply spelling out text.

41 lines (40 loc) 1.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("./utils"); class State { constructor(writer) { this.nGhosts = 0; this.isTyping = false; this.isPaused = false; this.finished = false; this.writer = writer; this.maxGhosts = this.writer.options.genMaxGhosts; } get ghostsInLimit() { return this.nGhosts < this.maxGhosts; } play() { this.isTyping = true; this.isPaused = false; this.finished = false; this.toggleClass(true); this.maxGhosts = this.writer.options.genMaxGhosts; } pause() { this.isTyping = false; this.isPaused = true; this.toggleClass(false); } finish() { this.isTyping = false; this.finished = true; this.toggleClass(false); } toggleClass(enable) { const el = this.writer.htmlElement, className = 'gw-writing'; if (!el) return; enable ? utils_1.animateWithClass(el, className) : el.classList.remove(className); } } exports.default = State;