1.0.4 • Published 3 years ago

text-typers v1.0.4

Weekly downloads
5
License
MIT
Repository
github
Last release
3 years ago

⌨️ Text Typer ⌨️

Demonstration of TextTyper in gif format

Links

Usage

Simply put the script tag into your HTML document. Module will be loaded via CDN

<script src='https://unpkg.com/text-typers@latest/build/bundle.js'></script>

Example

const tt = new TextTyper( document.getElementById('test') );

tt.eventQueue()
    .typeText('Hello World!')
    .standby(1000)
    .deleteChar()
    .standby(500)
    .typeText('Text Typer! ✏')
    .start();

Non-Chainable Methods

Those methods upon called, will perform the event immediately, asynchronously. Usually, you would want to use Chainable Methods instead.

MethodParametersDescriptionExample
constructortextBox - Targeted HTML element to type text in. TextBoxSettings (optional) - See more in TextBoxSettings.Constructor. Initializes a Text Typer on the target HTML element to be the text box (The HTML element that text will be typed inconst tt = new TextTyper(document.getElementById('my-box') );
typeTextstring - The text to be typed one by one into text box Types the string provided into the text boxtt.typeText('Hello World');
putTextstring - The text to be put into text boxPut the string immediately into the text box.tt.putText('Hello World');
deleteCharcount (optional) - Number of characters to be deleted. If exceeds the number of existing characters, it will simply stop after all characters are deleted. If no argument given, it will delete everything inside the text box one by oneDeletes the specified number of characters from the text box.tt.deleteChar(); tt.deletecChar(10);
clearText-Clears the textbox immediatelytt.clearText();
settingsTextBoxSettingsChange the settings of the Text typerSee Settings
presetThemetheme - The theme to be applied to the textbox. See SettingsApplies a Preset Theme to the text box.See Settings
eventQueue-Initializes and returns the Event Queue to obtain the ability to chain eventsconst eq = tt.eventQueue();

Chainable Methods

With eventQueue() called, it will return a CursorEventQueue object which you can chain events and have them execute one after another synchronously.

Most of the methods mentioned above in Non-Chainable Methods are also chainable for CursorEventQueue.

MethodParametersDescriptionExample
start-Starts the event queue, in one passeq.typeText("Hello World!").start();
loopcount (optional) - Number of times to loop. If no arguments specified, will loop for infinite times.Adds a loop event to the event queue. It will loop everything currently in the event queue for specified number of times. Note that after loop, the events are cleared.eq.typeText("a").loop(3).start(); // This will cause 'aaaa' to be typed
standbytime - Time in milliseconds for the stand by durationHold for specified milliseconds before execution of next event in the queueeq.standby(3000)
clearHistory-Clears the current history queue, so previously queued events won't be executed in the upcoming loopeq.typeText('a').clearHistory().loop().start() // Only single 'a' will be typed
typeTextstring - The text to be typed one by one into text box Types the string provided into the text boxeq.typeText('Hello World')
putTextstring - The text to be put into text boxPut the string immediately into the text box.eq.putText('Hello World')
deleteCharcount (optional) - Number of characters to be deleted. If exceeds the number of existing characters, it will simply stop after all characters are deleted. If no argument given, it will delete everything inside the text box one by oneDeletes the specified number of characters from the text box.eq.deleteChar(); eq.deleteChar(10)
clearText-Clears the textbox immediatelytt.clearText();
settingsTextBoxSettingsChange the settings of the Text typerSee Settings
presetThemetheme - The theme to be applied to the textbox. See Setting ConstantsApplies a Preset Theme to the text box.See Setting Constants
eventQueue-Initializes and returns the Event Queue to obtain the ability to chain eventsconst eq = tt.eventQueue();

Settings

This module comes with several settings that you can set to customize the behavior and look of the cursor.

First, familiarize yourself with format of the settings javascript object:

  • CursorSettings

{ blinkMode, blinkPeriod, cursorStyling }
PropertyDescription
blinkModeA string constant. Will determine the cursor blinking behavior. Explained in Setting Constants
blinkPeriodTime taken to complete one cycle of blinking (dissapear and reappear of Cursor), in milliseconds.
cursorStylingA string constant. Will style the cursor. Explained in Setting Constants
  • TextBoxSettings

{ typeCPS, deleteCPS, cursorSettings }
PropertyDescription
typeCPSNumber. Characters per second for typing
deleteCPSNumber. Characters per second for deleting
cursorSettingsCursorSettings Object

Setting Constants

Constants to be used in settings. Accessed via static class property - TextTyper.YOUR_CONSTANT_HERE

  1. blinkMode constants
    • TextTyper.CURSOR_BLINK_FLASH - Cursor dissapears suddenly, then reappears. Very commonly seen
    • TextTyper.CURSOR_BLINK_LINEAR - Cursor transitions to opacity 0 then transition to opacity 1
    • TextTyper.CURSOR_BLINK_NONE - Cursor will not blink at all
  2. cursorStyling constants
    • TextTyper.CURSOR_STYLE_BLOCK - Cursor appear as a rectangular, filled block
    • TextTyper.CURSOR_STYLE_I - Cursor appear capital i shaped
    • TextTyper.CURSOR_STYLE_LEFTARR - Cursor appear as <
    • TextTyper.CURSOR_STYLE_NONE - Cursor becomes invisible
    • TextTyper.CURSOR_STYLE_VERT - Cursor appear | shaped
    • TextTyper.CURSOR_STYLE_Y - Cursor appear capital i shaped, but top and buttom is curved
    • TextTyper.CURSOR_STYLE__ - Cursor appear as underscore shaped, _
  3. presetTheme constants
    • TextTyper.TBOX_THEME_DARK - Dark background green text
    • TextTyper.TBOX_THEME_DEFAULT - Default theme

Extensions

You can extend the functionality of this module through extensions!

  1. Sound Extension
1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago