UNPKG

glitched-writer

Version:

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

40 lines (39 loc) 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("./utils"); class default_1 { constructor(writer, onStepCallback, onFinishCallback) { this.onStepCallback = onStepCallback; this.onFinishCallback = onFinishCallback; this.writer = writer; } call(eventType) { var _a, _b; this.writer.updateString(); const { htmlElement, writerData, string } = this.writer; if (htmlElement && !this.writer.options.letterize) { if (this.writer.options.html) htmlElement.innerHTML = string; else htmlElement.textContent = string; } htmlElement === null || htmlElement === void 0 ? void 0 : htmlElement.setAttribute('data-gw-string', this.writer.options.html ? utils_1.filterHtml(string) : string); if (eventType === 'finish') { // ON FINISH this.writer.state.finish(); (_a = this.onFinishCallback) === null || _a === void 0 ? void 0 : _a.call(this, string, writerData); this.emitEvent(); } else { // ON STEP (_b = this.onStepCallback) === null || _b === void 0 ? void 0 : _b.call(this, string, writerData); } } emitEvent() { const { htmlElement, writerData } = this.writer; if (!htmlElement || typeof CustomEvent === 'undefined') return; htmlElement === null || htmlElement === void 0 ? void 0 : htmlElement.dispatchEvent(new CustomEvent('gw-finished', { detail: writerData })); } } exports.default = default_1;