diff --git a/packages/typeit/package-lock.json b/packages/typeit/package-lock.json index 2d994f35..006c43c6 100644 --- a/packages/typeit/package-lock.json +++ b/packages/typeit/package-lock.json @@ -1,12 +1,12 @@ { "name": "typeit", - "version": "8.5.1", + "version": "8.5.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "typeit", - "version": "8.5.1", + "version": "8.5.4", "hasInstallScript": true, "license": "GPL-3.0", "devDependencies": { diff --git a/packages/typeit/package.json b/packages/typeit/package.json index c6e7ea3a..0ae65eb7 100644 --- a/packages/typeit/package.json +++ b/packages/typeit/package.json @@ -1,6 +1,6 @@ { "name": "typeit", - "version": "8.5.3", + "version": "8.5.4", "description": "The most versatile animated typing utility on the planet.", "author": "Alex MacArthur (https://macarthur.me)", "license": "GPL-3.0", diff --git a/packages/typeit/src/Queue.ts b/packages/typeit/src/Queue.ts index 2db17fe9..d6006387 100644 --- a/packages/typeit/src/Queue.ts +++ b/packages/typeit/src/Queue.ts @@ -20,7 +20,7 @@ let Queue = function (initialItems: QueueItem[]) { * Given an index, set an item in the queue. */ let set = function (index: number, item: QueueItem): void { - let keys = _q.keys(); + let keys = [..._q.keys()]; _q.set(keys[index], item); }; diff --git a/packages/typeit/src/index.ts b/packages/typeit/src/index.ts index c842049a..209f7c1e 100644 --- a/packages/typeit/src/index.ts +++ b/packages/typeit/src/index.ts @@ -184,12 +184,13 @@ const TypeIt: TypeItInstance = function (element, options = {}) { let derivedCursorPosition = _getDerivedCursorPosition(); derivedCursorPosition && (await _move({ value: derivedCursorPosition })); - for (let _i of _queue.getTypeable()) { + // Grab all characters currently mounted to the DOM, + // in order to wipe the slate clean before restarting. + for (let _i of _getAllChars()) { await _wait(_delete, _getPace(1)); } _queue.reset(); - _queue.set(0, { delay }); }; @@ -246,7 +247,13 @@ const TypeIt: TypeItInstance = function (element, options = {}) { if (queueItem.typeable && !_statuses.frozen) _disableCursorBlink(true); - await fireItem(queueItem, _wait); + // Because calling .delete() with no parameters will attempt to + // delete all "typeable" characters, we may overfetch, since some characters + // in the queue may already be deleted. This ensures that we do not attempt to + // delete a character that isn't actually mounted to the DOM. + if (!queueItem.deletable || (queueItem.deletable && _getAllChars().length)) { + await fireItem(queueItem, _wait); + } _disableCursorBlink(false); @@ -366,6 +373,7 @@ const TypeIt: TypeItInstance = function (element, options = {}) { { func: _delete, delay: instant ? 0 : _getPace(1), + deletable: true }, rounds ), diff --git a/packages/typeit/src/types.ts b/packages/typeit/src/types.ts index aee7a68f..ec806b1a 100644 --- a/packages/typeit/src/types.ts +++ b/packages/typeit/src/types.ts @@ -43,6 +43,7 @@ export type QueueItem = { delay?: number; char?: any; typeable?: boolean; + deletable?: boolean; }; export type Element = HTMLElement &