typed.js 2.0.0 → 2.0.1-3.1

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 (57) hide show
  1. package/LICENSE.txt +1 -1
  2. package/README.md +117 -79
  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 +131 -0
  10. package/package.json +22 -24
  11. package/.codeclimate.yml +0 -30
  12. package/.csslintrc +0 -2
  13. package/.esdoc.json +0 -4
  14. package/.eslintignore +0 -2
  15. package/.eslintrc.yml +0 -21
  16. package/.npmignore +0 -4
  17. package/.travis.yml +0 -18
  18. package/.vscode/launch.json +0 -14
  19. package/.vscode/settings.json +0 -11
  20. package/bower.json +0 -16
  21. package/docs/API.md +0 -221
  22. package/docs/assets/anchor.js +0 -197
  23. package/docs/assets/bass-addons.css +0 -12
  24. package/docs/assets/bass.css +0 -543
  25. package/docs/assets/fonts/EOT/SourceCodePro-Bold.eot +0 -0
  26. package/docs/assets/fonts/EOT/SourceCodePro-Regular.eot +0 -0
  27. package/docs/assets/fonts/LICENSE.txt +0 -93
  28. package/docs/assets/fonts/OTF/SourceCodePro-Bold.otf +0 -0
  29. package/docs/assets/fonts/OTF/SourceCodePro-Regular.otf +0 -0
  30. package/docs/assets/fonts/TTF/SourceCodePro-Bold.ttf +0 -0
  31. package/docs/assets/fonts/TTF/SourceCodePro-Regular.ttf +0 -0
  32. package/docs/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff +0 -0
  33. package/docs/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff +0 -0
  34. package/docs/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff +0 -0
  35. package/docs/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff +0 -0
  36. package/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2 +0 -0
  37. package/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2 +0 -0
  38. package/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2 +0 -0
  39. package/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2 +0 -0
  40. package/docs/assets/fonts/source-code-pro.css +0 -23
  41. package/docs/assets/github.css +0 -123
  42. package/docs/assets/site.js +0 -108
  43. package/docs/assets/style.css +0 -136
  44. package/docs/index.html +0 -2138
  45. package/gulpfile.js +0 -61
  46. package/index.html +0 -110
  47. package/lib/typed.js +0 -989
  48. package/lib/typed.min.js +0 -11
  49. package/lib/typed.min.js.map +0 -1
  50. package/logo-cropped.png +0 -0
  51. package/logo.png +0 -0
  52. package/main.css +0 -44
  53. package/src/defaults.js +0 -151
  54. package/src/html-parser.js +0 -68
  55. package/src/initializer.js +0 -133
  56. package/src/typed.js +0 -396
  57. package/webpack.config.js +0 -47
package/src/typed.js DELETED
@@ -1,396 +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
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 & begin Typed from the start
65
- * @public
66
- */
67
- reset(restart = true) {
68
- clearInterval(this.timeout);
69
- this.replaceText('');
70
- if (this.cursor && this.cursor.parentNode) {
71
- this.cursor.parentNode.removeChild(this.cursor);
72
- }
73
- this.strPos = 0;
74
- this.arrayPos = 0;
75
- this.curLoop = 0;
76
- if (restart) {
77
- this.options.onReset(this);
78
- this.begin();
79
- }
80
- }
81
-
82
- /**
83
- * Begins the typing animation
84
- * @private
85
- */
86
- begin() {
87
- this.typingComplete = false;
88
- this.shuffleStringsIfNeeded(this);
89
- this.insertCursor();
90
- if (this.bindInputFocusEvents) this.bindFocusEvents();
91
- this.timeout = setTimeout(() => {
92
- // Check if there is some text in the element, if yes start by backspacing the default message
93
- if (!this.currentElContent || this.currentElContent.length === 0) {
94
- this.typewrite(this.strings[this.sequence[this.arrayPos]], this.strPos);
95
- } else {
96
- // Start typing
97
- this.backspace(this.currentElContent, this.currentElContent.length);
98
- }
99
- }, this.startDelay);
100
- }
101
-
102
- /**
103
- * Called for each character typed
104
- * @param {string} curString the current string in the strings array
105
- * @param {number} curStrPos the current position in the curString
106
- * @private
107
- */
108
- typewrite(curString, curStrPos) {
109
- if (this.fadeOut && this.el.classList.contains(this.fadeOutClass)) {
110
- this.el.classList.remove(this.fadeOutClass);
111
- this.cursor.classList.remove(this.fadeOutClass);
112
- }
113
-
114
- const humanize = this.humanizer(this.typeSpeed);
115
-
116
- if (this.pause.status === true) {
117
- this.setPauseStatus(curString, curStrPos, true);
118
- return;
119
- }
120
-
121
- // contain typing function in a timeout humanize'd delay
122
- this.timeout = setTimeout(() => {
123
- // check for an escape character before a pause value
124
- // format: \^\d+ .. eg: ^1000 .. should be able to print the ^ too using ^^
125
- // single ^ are removed from string
126
- let pauseTime = 0;
127
- let substr = curString.substr(curStrPos);
128
- if (substr.charAt(0) === '^') {
129
- let skip = 1; // skip atleast 1
130
- if (/^\^\d+/.test(substr)) {
131
- substr = /\d+/.exec(substr)[0];
132
- skip += substr.length;
133
- pauseTime = parseInt(substr);
134
- this.temporaryPause = true;
135
- this.options.onTypingPaused(this.arrayPos, this);
136
- }
137
- this.toggleBlinking(true);
138
-
139
- // strip out the escape character and pause value so they're not printed
140
- curString = curString.substring(0, curStrPos) + curString.substring(curStrPos + skip);
141
- }
142
-
143
- curStrPos = htmlParser.typeHtmlChars(curString, curStrPos, this);
144
-
145
- // timeout for any pause after a character
146
- this.timeout = setTimeout(() => {
147
- // Accounts for blinking while paused
148
- this.toggleBlinking(false);
149
-
150
- // We're done with this sentence!
151
- if (curStrPos === curString.length) {
152
- this.doneTyping(curString, curStrPos);
153
- } else {
154
- this.keepTyping(curString, curStrPos);
155
- }
156
- // end of character pause
157
- if (this.temporaryPause) {
158
- this.temporaryPause = false;
159
- this.options.onTypingResumed(this.arrayPos, this);
160
- }
161
- }, pauseTime);
162
-
163
- // humanized value for typing
164
- }, humanize);
165
- }
166
-
167
- /**
168
- * Continue to the next string & begin typing
169
- * @param {string} curString the current string in the strings array
170
- * @param {number} curStrPos the current position in the curString
171
- * @private
172
- */
173
- keepTyping(curString, curStrPos) {
174
- // call before functions if applicable
175
- if (curStrPos === 0) {
176
- this.toggleBlinking(false);
177
- this.options.preStringTyped(this.arrayPos, this);
178
- }
179
- // start typing each new char into existing string
180
- // curString: arg, this.el.html: original text inside element
181
- const nextString = curString.substr(0, curStrPos + 1);
182
- this.replaceText(nextString);
183
- // add characters one by one
184
- curStrPos++;
185
- // loop the function
186
- this.typewrite(curString, curStrPos);
187
- }
188
-
189
- /**
190
- * We're done typing all strings
191
- * @param {string} curString the current string in the strings array
192
- * @param {number} curStrPos the current position in the curString
193
- * @private
194
- */
195
- doneTyping(curString, curStrPos) {
196
- // fires callback function
197
- this.options.onStringTyped(this.arrayPos, this);
198
- this.toggleBlinking(true);
199
- // is this the final string
200
- if (this.arrayPos === this.strings.length - 1) {
201
- // callback that occurs on the last typed string
202
- this.complete();
203
- // quit if we wont loop back
204
- if (this.loop === false || this.curLoop === this.loopCount) {
205
- return;
206
- }
207
- }
208
- this.timeout = setTimeout(() => {
209
- this.backspace(curString, curStrPos);
210
- }, this.backDelay);
211
- }
212
-
213
- /**
214
- * Backspaces 1 character at a time
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
- backspace(curString, curStrPos) {
220
- if (this.pause.status === true) {
221
- this.setPauseStatus(curString, curStrPos, true);
222
- return;
223
- }
224
- if (this.fadeOut) return this.initFadeOut();
225
-
226
- this.toggleBlinking(false);
227
- const humanize = this.humanizer(this.backSpeed);
228
-
229
- this.timeout = setTimeout(() => {
230
- curStrPos = htmlParser.backSpaceHtmlChars(curString, curStrPos, this);
231
- // replace text with base text + typed characters
232
- const nextString = curString.substr(0, curStrPos);
233
- this.replaceText(nextString);
234
-
235
- // if smartBack is enabled
236
- if (this.smartBackspace) {
237
- // the remaining part of the current string is equal of the same part of the new string
238
- if (nextString === this.strings[this.arrayPos + 1].substr(0, curStrPos)) {
239
- this.stopNum = curStrPos;
240
- } else {
241
- this.stopNum = 0;
242
- }
243
- }
244
-
245
- // if the number (id of character in current string) is
246
- // less than the stop number, keep going
247
- if (curStrPos > this.stopNum) {
248
- // subtract characters one by one
249
- curStrPos--;
250
- // loop the function
251
- this.backspace(curString, curStrPos);
252
- } else if (curStrPos <= this.stopNum) {
253
- // if the stop number has been reached, increase
254
- // array position to next string
255
- this.arrayPos++;
256
- // When looping, begin at the beginning after backspace complete
257
- if (this.arrayPos === this.strings.length) {
258
- this.arrayPos = 0;
259
- this.options.onLastStringBackspaced();
260
- this.shuffleStringsIfNeeded();
261
- this.begin();
262
- } else {
263
- this.typewrite(this.strings[this.sequence[this.arrayPos]], curStrPos);
264
- }
265
- }
266
- // humanized value for typing
267
- }, humanize);
268
- }
269
-
270
- /**
271
- * Full animation is complete
272
- * @private
273
- */
274
- complete() {
275
- this.options.onComplete(this);
276
- if (this.loop) {
277
- this.curLoop++;
278
- } else {
279
- this.typingComplete = true;
280
- }
281
- }
282
-
283
- /**
284
- * Has the typing been stopped
285
- * @param {string} curString the current string in the strings array
286
- * @param {number} curStrPos the current position in the curString
287
- * @param {boolean} isTyping
288
- * @private
289
- */
290
- setPauseStatus(curString, curStrPos, isTyping) {
291
- this.pause.typewrite = isTyping;
292
- this.pause.curString = curString;
293
- this.pause.curStrPos = curStrPos;
294
- }
295
-
296
- /**
297
- * Toggle the blinking cursor
298
- * @param {boolean} isBlinking
299
- * @private
300
- */
301
- toggleBlinking(isBlinking) {
302
- if (!this.cusror) return;
303
- // if in paused state, don't toggle blinking a 2nd time
304
- if (this.pause.status) return;
305
- if (this.cursorBlinking === isBlinking) return;
306
- this.cursorBlinking = isBlinking;
307
- const status = isBlinking ? 'infinite' : 0;
308
- this.cursor.style.animationIterationCount = status;
309
- }
310
-
311
- /**
312
- * Speed in MS to type
313
- * @param {number} speed
314
- * @private
315
- */
316
- humanizer(speed) {
317
- return Math.round(Math.random() * speed / 2) + speed;
318
- }
319
-
320
- /**
321
- * Shuffle the sequence of the strings array
322
- * @private
323
- */
324
- shuffleStringsIfNeeded() {
325
- if (!this.shuffle) return;
326
- this.sequence = this.sequence.sort(() => Math.random() - 0.5);
327
- }
328
-
329
- /**
330
- * Adds a CSS class to fade out current string
331
- * @private
332
- */
333
- initFadeOut() {
334
- this.el.className += ` ${this.fadeOutClass}`;
335
- this.cursor.className += ` ${this.fadeOutClass}`;
336
- return setTimeout(() => {
337
- this.arrayPos++;
338
- this.replaceText('');
339
-
340
- // Resets current string if end of loop reached
341
- if (this.strings.length > this.arrayPos) {
342
- this.typewrite(this.strings[this.sequence[this.arrayPos]], 0);
343
- } else {
344
- this.typewrite(this.strings[0], 0);
345
- this.arrayPos = 0;
346
- }
347
- }, this.fadeOutDelay);
348
- }
349
-
350
- /**
351
- * Replaces current text in the HTML element
352
- * depending on element type
353
- * @param {string} str
354
- * @private
355
- */
356
- replaceText(str) {
357
- if (this.attr) {
358
- this.el.setAttribute(this.attr, str);
359
- } else {
360
- if (this.isInput) {
361
- this.el.value = str;
362
- } else if (this.contentType === 'html') {
363
- this.el.innerHTML = str;
364
- } else {
365
- this.el.textContent = str;
366
- }
367
- }
368
- }
369
-
370
- /**
371
- * If using input elements, bind focus in order to
372
- * start and stop the animation
373
- * @private
374
- */
375
- bindFocusEvents() {
376
- if (!this.isInput) return;
377
- this.el.addEventListener('focus', (e) => {
378
- this.stop();
379
- });
380
- this.el.addEventListener('blur', (e) => {
381
- this.start();
382
- });
383
- }
384
-
385
- /**
386
- * On init, insert the cursor element
387
- * @private
388
- */
389
- insertCursor() {
390
- if (!this.showCursor) return;
391
- this.cursor = document.createElement('span');
392
- this.cursor.className = 'typed-cursor';
393
- this.cursor.innerHTML = this.cursorChar;
394
- this.el.parentNode && this.el.parentNode.insertBefore(this.cursor, this.el.nextSibling);
395
- }
396
- }
package/webpack.config.js DELETED
@@ -1,47 +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: [
45
- new webpack.BannerPlugin(banner)
46
- ]
47
- };