1.0.4 • Published 4 years ago

markupwriter v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

markupwriter · npm version npm.io

markupwriter is a javascript library that lets you animate your html code snippet as raw text and render it at the same time, just as if you were writing it live. It's super lightweight, written in pure JS, using ES6 promises and native asynchronous functions to get the animation effect.

Example

Before anything, please check out this example page I put together to better understand what effect can you achieve by using this library.

Installation and usage with npm

Note: basic webpack configuration is required when using npm with this library.

Instalation

npm install markupwriter

Usage

index.html

<!DOCTYPE html>
<html>
  <head>
    <title>markupwriter - basic usage</title>
  </head>
  <body>
    <div class="rendered-html"></div>
    <div class="raw-html"></div>
	
	<!-- Path to your bundled script -->
	<script src="./build/bundle.js" type="text/javascript"></script>
  </body>
</html>

index.js

import MarkupWriter from 'markupwriter';

const renderedHtmlContainer = document.querySelector('.rendered-html');
const rawHtmlContainer = document.querySelector('.raw-html');
const htmlString = `
<div class="container">
	<h1>Hey there</h1>
	<p>This is some cool stuff going on here</p>
</div>
`;

const markupWriter = new MarkupWriter(
  renderedHtmlContainer,
  rawHtmlContainer,
  htmlString
);

markupWriter.start();

Open index.html file in the browser enviroment to see the result.

Usage with CDN

This approach doesn't require webpack or even an npm project.

index.html

<!DOCTYPE html>
<html>
  <head>
    <title>markupwriter - basic usage</title>
  </head>
  <body>
    <div class="rendered-html"></div>
    <div class="raw-html"></div>
	
	<!-- markupwriter lib -->
    <script
      src="https://cdn.jsdelivr.net/npm/markupwriter"
      type="text/javascript"
    ></script>
	
    <script src="index.js" type="text/javascript"></script>
  </body>
</html>

index.js

const renderedHtmlContainer = document.querySelector('.rendered-html');
const rawHtmlContainer = document.querySelector('.raw-html');
const htmlString = `
<div class="container">
	<h1>Hey there</h1>
	<p>This is some cool stuff going on here</p>
</div>
`;

/* MarkupWriter is a global object existing in the browser */

const markupWriter = new MarkupWriter(
  renderedHtmlContainer,
  rawHtmlContainer,
  htmlString
);

markupWriter.start();

Open index.html file in the browser enviroment to see the result.

Configuration

As a fourth argument to the MarkupWriter constructor you can optionally pass a configuration object.

Possible config options

PropertyTypeDescriptionDefault value
charIntervalnumberInterval in miliseconds between each character rendered90
charactersPerLinenumberNumber of characters per line after which script will look to make a break to new line50
displayCursorbooleanWhether to display cursor in raw html animation or nottrue
cursorOptionsobjectMore configuration around cursor-
cursorOptions.cursorStringstringString which will be rendered as cursor, can contain html<span class="markupwriter-cursor">|</span>
cursorOptions.colorstringValid css color string for the cursorrgb(252, 186, 3)
cursorOptions.animationSpeednumberBlinking animation duration in seconds1
cursorOptions.isStaticbooleanWhether or not cursor should render just once or rerender with every character animatedfalse
pauseBeforeTagOpennumberPause in miliseconds before opening new html tag500
pauseAfterTagClosenumberPause in miliseconds after closing html tag180
increasingPaceobjectConfiguration of increasing animation speed with every new character in the same node-
increasingPace.usebooleanWhether or not to use this effect at alltrue
increasingPace.multipliernumberMultiplier of charInterval, less = faster increase with every new character rendered in the same node0.99
increasingPace.maximumTimesChangenumberTimes speed increase cap2.2
onFinishfunctionCallback when animation finishes() => {}

Example usage with configuration object

index.js

import MarkupWriter from 'markupwriter';

const renderedHtmlContainer = document.querySelector('.rendered-html');
const rawHtmlContainer = document.querySelector('.raw-html');
const htmlString = `
<div class="container">
	<h1>Hey there</h1>
	<p>This is some cool stuff going on here</p>
</div>
`;

const config = {
  charInterval: 150,
  cursorOptions: {
    cursorString: '<h1>!</h1>',
    color: 'red'
  },
  onFinish: () => {
    alert('End of story');
  }
};

const markupWriter = new MarkupWriter(
  renderedHtmlContainer,
  rawHtmlContainer,
  htmlString,
  config
);

markupWriter.start();
1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago