UNPKG

glitched-writer

Version:

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

72 lines (71 loc) 3.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); // eslint-disable-next-line import/no-extraneous-dependencies const utils_1 = require("./utils"); const presets_1 = require("./presets"); class Options { constructor(writer, options) { 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; this.interval = (_b = options.interval) !== null && _b !== void 0 ? _b : presets_1.presets.default.interval; this.initialDelay = (_c = options.initialDelay) !== null && _c !== void 0 ? _c : presets_1.presets.default.initialDelay; this.changeChance = (_d = options.changeChance) !== null && _d !== void 0 ? _d : presets_1.presets.default.changeChance; this.ghostChance = (_e = options.ghostChance) !== null && _e !== void 0 ? _e : presets_1.presets.default.ghostChance; this.maxGhosts = (_f = options.maxGhosts) !== null && _f !== void 0 ? _f : presets_1.presets.default.maxGhosts; this.glyphs = (_g = options.glyphs) !== null && _g !== void 0 ? _g : presets_1.presets.default.glyphs; this.glyphsFromString = (_h = options.glyphsFromString) !== null && _h !== void 0 ? _h : presets_1.presets.default.glyphsFromString; 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 = (_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 = (_o = options.fillSpace) !== null && _o !== void 0 ? _o : presets_1.presets.default.fillSpace; } set glyphs(glyphs) { this.glyphsString = utils_1.parseCharset(glyphs); this.setCharset(); } set fillSpace(doFillSpace) { this.space = doFillSpace ? ' ' : ''; } get stepsLeft() { return utils_1.getRandomFromRange(this.steps); } get genInterval() { return utils_1.getRandomFromRange(this.interval); } get genInitDelay() { return utils_1.getRandomFromRange(this.initialDelay); } get genMaxGhosts() { if (Number.isInteger(this.maxGhosts)) return this.maxGhosts; let length; if (this.writer.options.html) length = utils_1.filterHtml(this.writer.goalString).length; else length = this.writer.goalString.length; return Math.round((length || 20) * this.maxGhosts); } get ghost() { var _a; return (_a = utils_1.getRandom(this.ghostCharset)) !== null && _a !== void 0 ? _a : ''; } setCharset() { let charset = this.glyphsString; if (this.glyphsFromString) charset += utils_1.filterDuplicates(this.writer.previousString + (this.writer.options.html ? utils_1.filterHtml(this.writer.goalString) : this.writer.goalString)); this.ghostCharset = [...charset].filter(l => !['\t', '\n', '\r', '\f', '\v'].includes(l)); } } exports.default = Options;