typed.js 2.0.12 → 2.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/LICENSE.txt +1 -1
  2. package/README.md +88 -37
  3. package/dist/typed.cjs +2 -0
  4. package/dist/typed.cjs.map +1 -0
  5. package/dist/typed.module.js +2 -0
  6. package/dist/typed.module.js.map +1 -0
  7. package/dist/typed.umd.js +3 -0
  8. package/dist/typed.umd.js.map +1 -0
  9. package/index.d.ts +253 -134
  10. package/package.json +21 -28
  11. package/.codeclimate.yml +0 -31
  12. package/.csslintrc +0 -2
  13. package/.esdoc.json +0 -4
  14. package/.eslintignore +0 -3
  15. package/.eslintrc.yml +0 -25
  16. package/.github/CONTRIBUTING.md +0 -44
  17. package/.github/ISSUE_TEMPLATE.md +0 -27
  18. package/.github/PULL_REQUEST_TEMPLATE.md +0 -38
  19. package/.prettierrc +0 -4
  20. package/.travis.yml +0 -16
  21. package/.vscode/launch.json +0 -14
  22. package/.vscode/settings.json +0 -11
  23. package/CODE_OF_CONDUCT.md +0 -46
  24. package/app.js +0 -12
  25. package/assets/demos.css +0 -61
  26. package/assets/demos.js +0 -133
  27. package/bower.json +0 -11
  28. package/docs/API.md +0 -231
  29. package/docs/assets/anchor.js +0 -197
  30. package/docs/assets/bass-addons.css +0 -12
  31. package/docs/assets/bass.css +0 -543
  32. package/docs/assets/fonts/EOT/SourceCodePro-Bold.eot +0 -0
  33. package/docs/assets/fonts/EOT/SourceCodePro-Regular.eot +0 -0
  34. package/docs/assets/fonts/LICENSE.txt +0 -93
  35. package/docs/assets/fonts/OTF/SourceCodePro-Bold.otf +0 -0
  36. package/docs/assets/fonts/OTF/SourceCodePro-Regular.otf +0 -0
  37. package/docs/assets/fonts/TTF/SourceCodePro-Bold.ttf +0 -0
  38. package/docs/assets/fonts/TTF/SourceCodePro-Regular.ttf +0 -0
  39. package/docs/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff +0 -0
  40. package/docs/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff +0 -0
  41. package/docs/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff +0 -0
  42. package/docs/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff +0 -0
  43. package/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2 +0 -0
  44. package/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2 +0 -0
  45. package/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2 +0 -0
  46. package/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2 +0 -0
  47. package/docs/assets/fonts/source-code-pro.css +0 -23
  48. package/docs/assets/github.css +0 -123
  49. package/docs/assets/site.js +0 -108
  50. package/docs/assets/style.css +0 -136
  51. package/docs/index.html +0 -2187
  52. package/gulpfile.js +0 -95
  53. package/index.html +0 -184
  54. package/lib/typed.js +0 -1052
  55. package/lib/typed.min.js +0 -11
  56. package/lib/typed.min.js.map +0 -1
  57. package/logo-cropped.png +0 -0
  58. package/logo.png +0 -0
  59. package/src/defaults.js +0 -164
  60. package/src/html-parser.js +0 -67
  61. package/src/initializer.js +0 -207
  62. package/src/typed.js +0 -433
  63. package/webpack.config.js +0 -45
package/src/typed.js DELETED
@@ -1,433 +0,0 @@
1
- import { initializer } from './initializer.js';
2
- import { htmlParser } from './html-parser.js';
3
-
4
- /**
5
- * Welcome to Typed.js!
6
- * @param {string} elementId HTML element ID _OR_ HTML element
7
- * @param {object} options options object
8
- * @returns {object} a new Typed object
9
- */
10
- export default class Typed {
11
- constructor(elementId, options) {
12
- // Initialize it up
13
- initializer.load(this, options, elementId);
14
- // All systems go!
15
- this.begin();
16
- }
17
-
18
- /**
19
- * Toggle start() and stop() of the Typed instance
20
- * @public
21
- */
22
- toggle() {
23
- this.pause.status ? this.start() : this.stop();
24
- }
25
-
26
- /**
27
- * Stop typing / backspacing and enable cursor blinking
28
- * @public
29
- */
30
- stop() {
31
- if (this.typingComplete) return;
32
- if (this.pause.status) return;
33
- this.toggleBlinking(true);
34
- this.pause.status = true;
35
- this.options.onStop(this.arrayPos, this);
36
- }
37
-
38
- /**
39
- * Start typing / backspacing after being stopped
40
- * @public
41
- */
42
- start() {
43
- if (this.typingComplete) return;
44
- if (!this.pause.status) return;
45
- this.pause.status = false;
46
- if (this.pause.typewrite) {
47
- this.typewrite(this.pause.curString, this.pause.curStrPos);
48
- } else {
49
- this.backspace(this.pause.curString, this.pause.curStrPos);
50
- }
51
- this.options.onStart(this.arrayPos, this);
52
- }
53
-
54
- /**
55
- * Destroy this instance of Typed
56
- * @public
57
- */
58
- destroy() {
59
- this.reset(false);
60
- this.options.onDestroy(this);
61
- }
62
-
63
- /**
64
- * Reset Typed and optionally restarts
65
- * @param {boolean} restart
66
- * @public
67
- */
68
- reset(restart = true) {
69
- clearInterval(this.timeout);
70
- this.replaceText('');
71
- if (this.cursor && this.cursor.parentNode) {
72
- this.cursor.parentNode.removeChild(this.cursor);
73
- this.cursor = null;
74
- }
75
- this.strPos = 0;
76
- this.arrayPos = 0;
77
- this.curLoop = 0;
78
- if (restart) {
79
- this.insertCursor();
80
- this.options.onReset(this);
81
- this.begin();
82
- }
83
- }
84
-
85
- /**
86
- * Begins the typing animation
87
- * @private
88
- */
89
- begin() {
90
- this.options.onBegin(this);
91
- this.typingComplete = false;
92
- this.shuffleStringsIfNeeded(this);
93
- this.insertCursor();
94
- if (this.bindInputFocusEvents) this.bindFocusEvents();
95
- this.timeout = setTimeout(() => {
96
- // Check if there is some text in the element, if yes start by backspacing the default message
97
- if (!this.currentElContent || this.currentElContent.length === 0) {
98
- this.typewrite(this.strings[this.sequence[this.arrayPos]], this.strPos);
99
- } else {
100
- // Start typing
101
- this.backspace(this.currentElContent, this.currentElContent.length);
102
- }
103
- }, this.startDelay);
104
- }
105
-
106
- /**
107
- * Called for each character typed
108
- * @param {string} curString the current string in the strings array
109
- * @param {number} curStrPos the current position in the curString
110
- * @private
111
- */
112
- typewrite(curString, curStrPos) {
113
- if (this.fadeOut && this.el.classList.contains(this.fadeOutClass)) {
114
- this.el.classList.remove(this.fadeOutClass);
115
- if (this.cursor) this.cursor.classList.remove(this.fadeOutClass);
116
- }
117
-
118
- const humanize = this.humanizer(this.typeSpeed);
119
- let numChars = 1;
120
-
121
- if (this.pause.status === true) {
122
- this.setPauseStatus(curString, curStrPos, true);
123
- return;
124
- }
125
-
126
- // contain typing function in a timeout humanize'd delay
127
- this.timeout = setTimeout(() => {
128
- // skip over any HTML chars
129
- curStrPos = htmlParser.typeHtmlChars(curString, curStrPos, this);
130
-
131
- let pauseTime = 0;
132
- let substr = curString.substr(curStrPos);
133
- // check for an escape character before a pause value
134
- // format: \^\d+ .. eg: ^1000 .. should be able to print the ^ too using ^^
135
- // single ^ are removed from string
136
- if (substr.charAt(0) === '^') {
137
- if (/^\^\d+/.test(substr)) {
138
- let skip = 1; // skip at least 1
139
- substr = /\d+/.exec(substr)[0];
140
- skip += substr.length;
141
- pauseTime = parseInt(substr);
142
- this.temporaryPause = true;
143
- this.options.onTypingPaused(this.arrayPos, this);
144
- // strip out the escape character and pause value so they're not printed
145
- curString =
146
- curString.substring(0, curStrPos) +
147
- curString.substring(curStrPos + skip);
148
- this.toggleBlinking(true);
149
- }
150
- }
151
-
152
- // check for skip characters formatted as
153
- // "this is a `string to print NOW` ..."
154
- if (substr.charAt(0) === '`') {
155
- while (curString.substr(curStrPos + numChars).charAt(0) !== '`') {
156
- numChars++;
157
- if (curStrPos + numChars > curString.length) break;
158
- }
159
- // strip out the escape characters and append all the string in between
160
- const stringBeforeSkip = curString.substring(0, curStrPos);
161
- const stringSkipped = curString.substring(
162
- stringBeforeSkip.length + 1,
163
- curStrPos + numChars
164
- );
165
- const stringAfterSkip = curString.substring(curStrPos + numChars + 1);
166
- curString = stringBeforeSkip + stringSkipped + stringAfterSkip;
167
- numChars--;
168
- }
169
-
170
- // timeout for any pause after a character
171
- this.timeout = setTimeout(() => {
172
- // Accounts for blinking while paused
173
- this.toggleBlinking(false);
174
-
175
- // We're done with this sentence!
176
- if (curStrPos >= curString.length) {
177
- this.doneTyping(curString, curStrPos);
178
- } else {
179
- this.keepTyping(curString, curStrPos, numChars);
180
- }
181
- // end of character pause
182
- if (this.temporaryPause) {
183
- this.temporaryPause = false;
184
- this.options.onTypingResumed(this.arrayPos, this);
185
- }
186
- }, pauseTime);
187
-
188
- // humanized value for typing
189
- }, humanize);
190
- }
191
-
192
- /**
193
- * Continue to the next string & begin typing
194
- * @param {string} curString the current string in the strings array
195
- * @param {number} curStrPos the current position in the curString
196
- * @private
197
- */
198
- keepTyping(curString, curStrPos, numChars) {
199
- // call before functions if applicable
200
- if (curStrPos === 0) {
201
- this.toggleBlinking(false);
202
- this.options.preStringTyped(this.arrayPos, this);
203
- }
204
- // start typing each new char into existing string
205
- // curString: arg, this.el.html: original text inside element
206
- curStrPos += numChars;
207
- const nextString = curString.substr(0, curStrPos);
208
- this.replaceText(nextString);
209
- // loop the function
210
- this.typewrite(curString, curStrPos);
211
- }
212
-
213
- /**
214
- * We're done typing the current string
215
- * @param {string} curString the current string in the strings array
216
- * @param {number} curStrPos the current position in the curString
217
- * @private
218
- */
219
- doneTyping(curString, curStrPos) {
220
- // fires callback function
221
- this.options.onStringTyped(this.arrayPos, this);
222
- this.toggleBlinking(true);
223
- // is this the final string
224
- if (this.arrayPos === this.strings.length - 1) {
225
- // callback that occurs on the last typed string
226
- this.complete();
227
- // quit if we wont loop back
228
- if (this.loop === false || this.curLoop === this.loopCount) {
229
- return;
230
- }
231
- }
232
- this.timeout = setTimeout(() => {
233
- this.backspace(curString, curStrPos);
234
- }, this.backDelay);
235
- }
236
-
237
- /**
238
- * Backspaces 1 character at a time
239
- * @param {string} curString the current string in the strings array
240
- * @param {number} curStrPos the current position in the curString
241
- * @private
242
- */
243
- backspace(curString, curStrPos) {
244
- if (this.pause.status === true) {
245
- this.setPauseStatus(curString, curStrPos, false);
246
- return;
247
- }
248
- if (this.fadeOut) return this.initFadeOut();
249
-
250
- this.toggleBlinking(false);
251
- const humanize = this.humanizer(this.backSpeed);
252
-
253
- this.timeout = setTimeout(() => {
254
- curStrPos = htmlParser.backSpaceHtmlChars(curString, curStrPos, this);
255
- // replace text with base text + typed characters
256
- const curStringAtPosition = curString.substr(0, curStrPos);
257
- this.replaceText(curStringAtPosition);
258
-
259
- // if smartBack is enabled
260
- if (this.smartBackspace) {
261
- // the remaining part of the current string is equal of the same part of the new string
262
- let nextString = this.strings[this.arrayPos + 1];
263
- if (
264
- nextString &&
265
- curStringAtPosition === nextString.substr(0, curStrPos)
266
- ) {
267
- this.stopNum = curStrPos;
268
- } else {
269
- this.stopNum = 0;
270
- }
271
- }
272
-
273
- // if the number (id of character in current string) is
274
- // less than the stop number, keep going
275
- if (curStrPos > this.stopNum) {
276
- // subtract characters one by one
277
- curStrPos--;
278
- // loop the function
279
- this.backspace(curString, curStrPos);
280
- } else if (curStrPos <= this.stopNum) {
281
- // if the stop number has been reached, increase
282
- // array position to next string
283
- this.arrayPos++;
284
- // When looping, begin at the beginning after backspace complete
285
- if (this.arrayPos === this.strings.length) {
286
- this.arrayPos = 0;
287
- this.options.onLastStringBackspaced();
288
- this.shuffleStringsIfNeeded();
289
- this.begin();
290
- } else {
291
- this.typewrite(this.strings[this.sequence[this.arrayPos]], curStrPos);
292
- }
293
- }
294
- // humanized value for typing
295
- }, humanize);
296
- }
297
-
298
- /**
299
- * Full animation is complete
300
- * @private
301
- */
302
- complete() {
303
- this.options.onComplete(this);
304
- if (this.loop) {
305
- this.curLoop++;
306
- } else {
307
- this.typingComplete = true;
308
- }
309
- }
310
-
311
- /**
312
- * Has the typing been stopped
313
- * @param {string} curString the current string in the strings array
314
- * @param {number} curStrPos the current position in the curString
315
- * @param {boolean} isTyping
316
- * @private
317
- */
318
- setPauseStatus(curString, curStrPos, isTyping) {
319
- this.pause.typewrite = isTyping;
320
- this.pause.curString = curString;
321
- this.pause.curStrPos = curStrPos;
322
- }
323
-
324
- /**
325
- * Toggle the blinking cursor
326
- * @param {boolean} isBlinking
327
- * @private
328
- */
329
- toggleBlinking(isBlinking) {
330
- if (!this.cursor) return;
331
- // if in paused state, don't toggle blinking a 2nd time
332
- if (this.pause.status) return;
333
- if (this.cursorBlinking === isBlinking) return;
334
- this.cursorBlinking = isBlinking;
335
- if (isBlinking) {
336
- this.cursor.classList.add('typed-cursor--blink');
337
- } else {
338
- this.cursor.classList.remove('typed-cursor--blink');
339
- }
340
- }
341
-
342
- /**
343
- * Speed in MS to type
344
- * @param {number} speed
345
- * @private
346
- */
347
- humanizer(speed) {
348
- return Math.round((Math.random() * speed) / 2) + speed;
349
- }
350
-
351
- /**
352
- * Shuffle the sequence of the strings array
353
- * @private
354
- */
355
- shuffleStringsIfNeeded() {
356
- if (!this.shuffle) return;
357
- this.sequence = this.sequence.sort(() => Math.random() - 0.5);
358
- }
359
-
360
- /**
361
- * Adds a CSS class to fade out current string
362
- * @private
363
- */
364
- initFadeOut() {
365
- this.el.className += ` ${this.fadeOutClass}`;
366
- if (this.cursor) this.cursor.className += ` ${this.fadeOutClass}`;
367
- return setTimeout(() => {
368
- this.arrayPos++;
369
- this.replaceText('');
370
-
371
- // Resets current string if end of loop reached
372
- if (this.strings.length > this.arrayPos) {
373
- this.typewrite(this.strings[this.sequence[this.arrayPos]], 0);
374
- } else {
375
- this.typewrite(this.strings[0], 0);
376
- this.arrayPos = 0;
377
- }
378
- }, this.fadeOutDelay);
379
- }
380
-
381
- /**
382
- * Replaces current text in the HTML element
383
- * depending on element type
384
- * @param {string} str
385
- * @private
386
- */
387
- replaceText(str) {
388
- if (this.attr) {
389
- this.el.setAttribute(this.attr, str);
390
- } else {
391
- if (this.isInput) {
392
- this.el.value = str;
393
- } else if (this.contentType === 'html') {
394
- this.el.innerHTML = str;
395
- } else {
396
- this.el.textContent = str;
397
- }
398
- }
399
- }
400
-
401
- /**
402
- * If using input elements, bind focus in order to
403
- * start and stop the animation
404
- * @private
405
- */
406
- bindFocusEvents() {
407
- if (!this.isInput) return;
408
- this.el.addEventListener('focus', (e) => {
409
- this.stop();
410
- });
411
- this.el.addEventListener('blur', (e) => {
412
- if (this.el.value && this.el.value.length !== 0) {
413
- return;
414
- }
415
- this.start();
416
- });
417
- }
418
-
419
- /**
420
- * On init, insert the cursor element
421
- * @private
422
- */
423
- insertCursor() {
424
- if (!this.showCursor) return;
425
- if (this.cursor) return;
426
- this.cursor = document.createElement('span');
427
- this.cursor.className = 'typed-cursor';
428
- this.cursor.setAttribute('aria-hidden', true);
429
- this.cursor.innerHTML = this.cursorChar;
430
- this.el.parentNode &&
431
- this.el.parentNode.insertBefore(this.cursor, this.el.nextSibling);
432
- }
433
- }
package/webpack.config.js DELETED
@@ -1,45 +0,0 @@
1
- import webpack from 'webpack';
2
- import pkg from './package.json';
3
- var banner = `
4
- ${pkg.name} - ${pkg.description}
5
- Author: ${pkg.author}
6
- Version: v${pkg.version}
7
- Url: ${pkg.homepage}
8
- License(s): ${pkg.license}
9
- `;
10
-
11
- export default {
12
- entry: {
13
- Typed: './src/typed.js'
14
- },
15
- output: {
16
- path: __dirname,
17
- library: 'Typed',
18
- libraryTarget: 'umd',
19
- filename: `typed.js`
20
- },
21
- devtool: '#inline-source-map',
22
- externals: [
23
- {
24
- lodash: {
25
- root: '_',
26
- commonjs: 'lodash',
27
- commonjs2: 'lodash',
28
- amd: 'lodash'
29
- }
30
- }
31
- ],
32
- module: {
33
- loaders: [
34
- {
35
- test: /\.js$/,
36
- exclude: /node_modules/,
37
- loader: 'babel',
38
- query: {
39
- compact: false
40
- }
41
- }
42
- ]
43
- },
44
- plugins: [new webpack.BannerPlugin(banner)]
45
- };