title-switcher 2.0.0 → 2.1.0
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.
- package/README.md +0 -148
- package/browser/titleSwitcher.js +154 -199
- package/browser/titleSwitcher.min.js +1 -1
- package/dist/main.d.ts +90 -0
- package/dist/main.js +154 -199
- package/dist/main.min.js +1 -1
- package/package.json +1 -1
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/*********************************************
|
|
2
|
+
Title Switcher: to imitate typing and switch to different titles based on DOM.
|
|
3
|
+
Requires titles to be listed as elements inside a div, pass the class of the div as an argument to TitleSwitcher.
|
|
4
|
+
**********************************************/
|
|
5
|
+
type switchTitleCallback = (domObject: HTMLElement | Element, callBackFunction: Function, self?: TitleSwitcher, runOnce?: boolean) => TitleSwitcher;
|
|
6
|
+
declare class TitleSwitcher {
|
|
7
|
+
#private;
|
|
8
|
+
cursorBlink: (blinkOn: boolean, self: TitleSwitcher) => TitleSwitcher;
|
|
9
|
+
typingEffect: switchTitleCallback;
|
|
10
|
+
/**
|
|
11
|
+
* Instantiate this as a class to get an instance of TitleSwitcher
|
|
12
|
+
* @param {string} [titlesContainer=''] - The selector where titles are stored
|
|
13
|
+
* @param {Function|string} [switchStyle='typingEffect'] - The function or function name for the effect to apply
|
|
14
|
+
* @constructor
|
|
15
|
+
*/
|
|
16
|
+
constructor(titlesContainer?: string, switchStyle?: switchTitleCallback | keyof TitleSwitcher | string);
|
|
17
|
+
/**
|
|
18
|
+
* Retrieve active
|
|
19
|
+
* @return {boolean}
|
|
20
|
+
*/
|
|
21
|
+
get active(): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Retrieve currentClass
|
|
24
|
+
* @return {string}
|
|
25
|
+
*/
|
|
26
|
+
get currentClass(): string;
|
|
27
|
+
/**
|
|
28
|
+
* Retrieve currentIndex
|
|
29
|
+
* @return {number}
|
|
30
|
+
*/
|
|
31
|
+
get currentIndex(): number;
|
|
32
|
+
/**
|
|
33
|
+
* Retrieve delayEffect
|
|
34
|
+
* @return {number}
|
|
35
|
+
*/
|
|
36
|
+
get delayEffect(): number;
|
|
37
|
+
/**
|
|
38
|
+
* Retrieve delaySwitch
|
|
39
|
+
* @return {number}
|
|
40
|
+
*/
|
|
41
|
+
get delaySwitch(): number;
|
|
42
|
+
/**
|
|
43
|
+
* Retrieve switchStyle
|
|
44
|
+
* @return {Function}
|
|
45
|
+
*/
|
|
46
|
+
get switchStyle(): Function;
|
|
47
|
+
/**
|
|
48
|
+
* Retrieve list of titles DOM elements
|
|
49
|
+
* @return {Array<HTMLElement>|HTMLCollection}
|
|
50
|
+
*/
|
|
51
|
+
get titles(): Array<HTMLElement> | HTMLCollection;
|
|
52
|
+
/**
|
|
53
|
+
* Retrieve typeSurface used
|
|
54
|
+
* @return {HTMLElement|null}
|
|
55
|
+
*/
|
|
56
|
+
get typeSurface(): HTMLElement | null;
|
|
57
|
+
/**
|
|
58
|
+
* This is the function to begin the switching titles
|
|
59
|
+
* @param {Object} [settings={}]
|
|
60
|
+
* @param {number} [settings.delaySwitch=400]
|
|
61
|
+
* @param {number} [settings.delayEffect=200]
|
|
62
|
+
* @param {boolean} [settings.isRandom=false]
|
|
63
|
+
* @param {boolean} [settings.immediatePause=false]
|
|
64
|
+
* @returns {TitleSwitcher}
|
|
65
|
+
*/
|
|
66
|
+
startTitles({ delaySwitch, delayEffect, isRandom, immediatePause }?: {
|
|
67
|
+
delaySwitch?: number;
|
|
68
|
+
delayEffect?: number;
|
|
69
|
+
isRandom?: boolean;
|
|
70
|
+
immediatePause?: boolean;
|
|
71
|
+
}): TitleSwitcher;
|
|
72
|
+
/**
|
|
73
|
+
* This is the function to pause between switching
|
|
74
|
+
*/
|
|
75
|
+
pause(): void;
|
|
76
|
+
/**
|
|
77
|
+
* This is the function to resume after a pause.
|
|
78
|
+
*/
|
|
79
|
+
resume(): void;
|
|
80
|
+
/**
|
|
81
|
+
* This is the core function for switching titles
|
|
82
|
+
* @param {HTMLElement} currentTitle
|
|
83
|
+
* @param {Function} callBackFunction
|
|
84
|
+
* @param {TitleSwitcher} self
|
|
85
|
+
* @param {boolean} [runOnce=false]
|
|
86
|
+
* @returns {TitleSwitcher}
|
|
87
|
+
*/
|
|
88
|
+
switchTitle(currentTitle: Element, callBackFunction: switchTitleCallback, self: this, runOnce?: boolean): TitleSwitcher;
|
|
89
|
+
}
|
|
90
|
+
export default TitleSwitcher;
|
package/dist/main.js
CHANGED
|
@@ -1,23 +1,13 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
// Created by Joshua Heagle
|
|
4
|
-
|
|
5
|
-
/*********************************************
|
|
6
|
-
Title Switcher: to imitate typing and switch to different titles based on DOM.
|
|
7
|
-
Requires titles to be listed as elements inside a div, pass the class of the div as an argument to TitleSwitcher.
|
|
8
|
-
**********************************************/
|
|
9
3
|
require('core-js/modules/es.symbol.to-primitive.js')
|
|
10
4
|
require('core-js/modules/es.date.to-primitive.js')
|
|
11
5
|
require('core-js/modules/es.symbol.js')
|
|
12
6
|
require('core-js/modules/es.symbol.description.js')
|
|
13
7
|
require('core-js/modules/es.number.constructor.js')
|
|
14
|
-
require('core-js/modules/es.object.define-property.js')
|
|
15
8
|
require('core-js/modules/es.symbol.iterator.js')
|
|
16
9
|
function _typeof (o) { '@babel/helpers - typeof'; return _typeof = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol' ? function (o) { return typeof o } : function (o) { return o && typeof Symbol === 'function' && o.constructor === Symbol && o !== Symbol.prototype ? 'symbol' : typeof o }, _typeof(o) }
|
|
17
|
-
|
|
18
|
-
value: true
|
|
19
|
-
})
|
|
20
|
-
exports.default = void 0
|
|
10
|
+
require('core-js/modules/es.object.define-property.js')
|
|
21
11
|
require('core-js/modules/es.regexp.exec.js')
|
|
22
12
|
require('core-js/modules/es.string.replace.js')
|
|
23
13
|
require('core-js/modules/es.regexp.constructor.js')
|
|
@@ -27,189 +17,153 @@ require('core-js/modules/es.array.join.js')
|
|
|
27
17
|
require('core-js/modules/es.array.for-each.js')
|
|
28
18
|
require('core-js/modules/es.object.to-string.js')
|
|
29
19
|
require('core-js/modules/es.string.trim.js')
|
|
30
|
-
require('core-js/modules/web.timers.js')
|
|
31
|
-
require('core-js/modules/esnext.async-iterator.for-each.js')
|
|
32
|
-
require('core-js/modules/esnext.iterator.constructor.js')
|
|
33
|
-
require('core-js/modules/esnext.iterator.for-each.js')
|
|
34
|
-
require('core-js/modules/web.dom-collections.for-each.js')
|
|
35
20
|
require('core-js/modules/es.array.iterator.js')
|
|
36
21
|
require('core-js/modules/es.string.iterator.js')
|
|
37
22
|
require('core-js/modules/es.weak-map.js')
|
|
38
23
|
require('core-js/modules/esnext.weak-map.delete-all.js')
|
|
39
24
|
require('core-js/modules/web.dom-collections.iterator.js')
|
|
25
|
+
require('core-js/modules/web.timers.js')
|
|
26
|
+
require('core-js/modules/esnext.async-iterator.for-each.js')
|
|
27
|
+
require('core-js/modules/esnext.iterator.constructor.js')
|
|
28
|
+
require('core-js/modules/esnext.iterator.for-each.js')
|
|
29
|
+
require('core-js/modules/web.dom-collections.for-each.js')
|
|
40
30
|
var _this = void 0
|
|
41
31
|
function _classCallCheck (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function') } }
|
|
42
32
|
function _defineProperties (target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor) } }
|
|
43
33
|
function _createClass (Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, 'prototype', { writable: false }); return Constructor }
|
|
44
34
|
function _toPropertyKey (arg) { var key = _toPrimitive(arg, 'string'); return _typeof(key) === 'symbol' ? key : String(key) }
|
|
45
35
|
function _toPrimitive (input, hint) { if (_typeof(input) !== 'object' || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || 'default'); if (_typeof(res) !== 'object') return res; throw new TypeError('@@toPrimitive must return a primitive value.') } return (hint === 'string' ? String : Number)(input) }
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
var
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
var _titlesContainer = /* #__PURE__ */new WeakMap()
|
|
62
|
-
var _typeSurface = /* #__PURE__ */new WeakMap()
|
|
36
|
+
var __classPrivateFieldSet = void 0 && (void 0).__classPrivateFieldSet || function (receiver, state, value, kind, f) {
|
|
37
|
+
if (kind === 'm') throw new TypeError('Private method is not writable')
|
|
38
|
+
if (kind === 'a' && !f) throw new TypeError('Private accessor was defined without a setter')
|
|
39
|
+
if (typeof state === 'function' ? receiver !== state || !f : !state.has(receiver)) throw new TypeError('Cannot write private member to an object whose class did not declare it')
|
|
40
|
+
return kind === 'a' ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value
|
|
41
|
+
}
|
|
42
|
+
var __classPrivateFieldGet = void 0 && (void 0).__classPrivateFieldGet || function (receiver, state, kind, f) {
|
|
43
|
+
if (kind === 'a' && !f) throw new TypeError('Private accessor was defined without a getter')
|
|
44
|
+
if (typeof state === 'function' ? receiver !== state || !f : !state.has(receiver)) throw new TypeError('Cannot read private member from an object whose class did not declare it')
|
|
45
|
+
return kind === 'm' ? f : kind === 'a' ? f.call(receiver) : f ? f.value : state.get(receiver)
|
|
46
|
+
}
|
|
47
|
+
var _TitleSwitcher_active, _TitleSwitcher_currentClass, _TitleSwitcher_currentIndex, _TitleSwitcher_delayEffect, _TitleSwitcher_delaySwitch, _TitleSwitcher_isRandom, _TitleSwitcher_titles, _TitleSwitcher_titlesContainer, _TitleSwitcher_switchStyle, _TitleSwitcher_typeSurface
|
|
48
|
+
Object.defineProperty(exports, '__esModule', {
|
|
49
|
+
value: true
|
|
50
|
+
})
|
|
63
51
|
var TitleSwitcher = /* #__PURE__ */(function () {
|
|
64
|
-
/**
|
|
65
|
-
* Instantiate this as a class to get an instance of TitleSwitcher
|
|
66
|
-
* @param {string} [titlesContainer=''] - The selector where titles are stored
|
|
67
|
-
* @param {Function|string} [switchStyle='typingEffect'] - The function or function name for the effect to apply
|
|
68
|
-
* @constructor
|
|
52
|
+
/**
|
|
53
|
+
* Instantiate this as a class to get an instance of TitleSwitcher
|
|
54
|
+
* @param {string} [titlesContainer=''] - The selector where titles are stored
|
|
55
|
+
* @param {Function|string} [switchStyle='typingEffect'] - The function or function name for the effect to apply
|
|
56
|
+
* @constructor
|
|
69
57
|
*/
|
|
70
58
|
function TitleSwitcher () {
|
|
71
59
|
var titlesContainer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''
|
|
72
60
|
var switchStyle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'typingEffect'
|
|
73
61
|
_classCallCheck(this, TitleSwitcher)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
})
|
|
94
|
-
_classPrivateFieldInitSpec(this, _isRandom, {
|
|
95
|
-
writable: true,
|
|
96
|
-
value: false
|
|
97
|
-
})
|
|
98
|
-
_classPrivateFieldInitSpec(this, _switchStyle, {
|
|
99
|
-
writable: true,
|
|
100
|
-
value: 'typingEffect'
|
|
101
|
-
})
|
|
102
|
-
_classPrivateFieldInitSpec(this, _titles, {
|
|
103
|
-
writable: true,
|
|
104
|
-
value: []
|
|
105
|
-
})
|
|
106
|
-
_classPrivateFieldInitSpec(this, _titlesContainer, {
|
|
107
|
-
writable: true,
|
|
108
|
-
value: null
|
|
109
|
-
})
|
|
110
|
-
_classPrivateFieldInitSpec(this, _typeSurface, {
|
|
111
|
-
writable: true,
|
|
112
|
-
value: void 0
|
|
113
|
-
})
|
|
114
|
-
_classPrivateFieldSet(this, _currentClass, 'displayTitle')
|
|
115
|
-
_classPrivateFieldSet(this, _switchStyle, this[typeof this[switchStyle] === 'function' ? switchStyle : 'typingEffect'])
|
|
116
|
-
_classPrivateFieldSet(this, _titlesContainer, titlesContainer)
|
|
117
|
-
_classPrivateFieldSet(this, _titles, [])
|
|
62
|
+
_TitleSwitcher_active.set(this, false)
|
|
63
|
+
_TitleSwitcher_currentClass.set(this, 'displayTitle')
|
|
64
|
+
_TitleSwitcher_currentIndex.set(this, 0)
|
|
65
|
+
_TitleSwitcher_delayEffect.set(this, 200)
|
|
66
|
+
_TitleSwitcher_delaySwitch.set(this, 400)
|
|
67
|
+
_TitleSwitcher_isRandom.set(this, false)
|
|
68
|
+
_TitleSwitcher_titles.set(this, [])
|
|
69
|
+
_TitleSwitcher_titlesContainer.set(this, null)
|
|
70
|
+
_TitleSwitcher_switchStyle.set(this, void 0)
|
|
71
|
+
_TitleSwitcher_typeSurface.set(this, void 0)
|
|
72
|
+
__classPrivateFieldSet(this, _TitleSwitcher_currentClass, 'displayTitle', 'f')
|
|
73
|
+
if (typeof switchStyle === 'string') {
|
|
74
|
+
// @ts-ignore Obnoxious error "type 'string' can't be used to index type 'TitleSwitcher'"
|
|
75
|
+
__classPrivateFieldSet(this, _TitleSwitcher_switchStyle, typeof this[switchStyle] === 'function' ? this[switchStyle] : this.typingEffect, 'f')
|
|
76
|
+
} else {
|
|
77
|
+
__classPrivateFieldSet(this, _TitleSwitcher_switchStyle, switchStyle, 'f')
|
|
78
|
+
}
|
|
79
|
+
__classPrivateFieldSet(this, _TitleSwitcher_titlesContainer, null, 'f')
|
|
80
|
+
__classPrivateFieldSet(this, _TitleSwitcher_titles, [], 'f')
|
|
118
81
|
var foundContainers = titlesContainer ? document.querySelectorAll(titlesContainer) : []
|
|
119
82
|
if (foundContainers && foundContainers[0]) {
|
|
120
|
-
|
|
121
|
-
|
|
83
|
+
__classPrivateFieldSet(this, _TitleSwitcher_titlesContainer, foundContainers[0], 'f')
|
|
84
|
+
__classPrivateFieldSet(this, _TitleSwitcher_titles, __classPrivateFieldGet(this, _TitleSwitcher_titlesContainer, 'f').children, 'f')
|
|
122
85
|
}
|
|
123
86
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
*
|
|
127
|
-
* @return {boolean}
|
|
87
|
+
/**
|
|
88
|
+
* Retrieve active
|
|
89
|
+
* @return {boolean}
|
|
128
90
|
*/
|
|
129
91
|
_createClass(TitleSwitcher, [{
|
|
130
92
|
key: 'active',
|
|
131
93
|
get: function get () {
|
|
132
|
-
return
|
|
94
|
+
return __classPrivateFieldGet(this, _TitleSwitcher_active, 'f')
|
|
133
95
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
*
|
|
137
|
-
* @return {string}
|
|
96
|
+
/**
|
|
97
|
+
* Retrieve currentClass
|
|
98
|
+
* @return {string}
|
|
138
99
|
*/
|
|
139
100
|
}, {
|
|
140
101
|
key: 'currentClass',
|
|
141
102
|
get: function get () {
|
|
142
|
-
return
|
|
103
|
+
return __classPrivateFieldGet(this, _TitleSwitcher_currentClass, 'f')
|
|
143
104
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
*
|
|
147
|
-
* @return {number}
|
|
105
|
+
/**
|
|
106
|
+
* Retrieve currentIndex
|
|
107
|
+
* @return {number}
|
|
148
108
|
*/
|
|
149
109
|
}, {
|
|
150
110
|
key: 'currentIndex',
|
|
151
111
|
get: function get () {
|
|
152
|
-
return
|
|
112
|
+
return __classPrivateFieldGet(this, _TitleSwitcher_currentIndex, 'f')
|
|
153
113
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
*
|
|
157
|
-
* @return {number}
|
|
114
|
+
/**
|
|
115
|
+
* Retrieve delayEffect
|
|
116
|
+
* @return {number}
|
|
158
117
|
*/
|
|
159
118
|
}, {
|
|
160
119
|
key: 'delayEffect',
|
|
161
120
|
get: function get () {
|
|
162
|
-
return
|
|
121
|
+
return __classPrivateFieldGet(this, _TitleSwitcher_delayEffect, 'f')
|
|
163
122
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
*
|
|
167
|
-
* @return {number}
|
|
123
|
+
/**
|
|
124
|
+
* Retrieve delaySwitch
|
|
125
|
+
* @return {number}
|
|
168
126
|
*/
|
|
169
127
|
}, {
|
|
170
128
|
key: 'delaySwitch',
|
|
171
129
|
get: function get () {
|
|
172
|
-
return
|
|
130
|
+
return __classPrivateFieldGet(this, _TitleSwitcher_delaySwitch, 'f')
|
|
173
131
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
*
|
|
177
|
-
* @return {string}
|
|
132
|
+
/**
|
|
133
|
+
* Retrieve switchStyle
|
|
134
|
+
* @return {Function}
|
|
178
135
|
*/
|
|
179
136
|
}, {
|
|
180
137
|
key: 'switchStyle',
|
|
181
138
|
get: function get () {
|
|
182
|
-
return
|
|
139
|
+
return __classPrivateFieldGet(this, _TitleSwitcher_switchStyle, 'f')
|
|
183
140
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
*
|
|
187
|
-
* @return {Array|NodeList}
|
|
141
|
+
/**
|
|
142
|
+
* Retrieve list of titles DOM elements
|
|
143
|
+
* @return {Array<HTMLElement>|HTMLCollection}
|
|
188
144
|
*/
|
|
189
145
|
}, {
|
|
190
146
|
key: 'titles',
|
|
191
147
|
get: function get () {
|
|
192
|
-
return
|
|
148
|
+
return __classPrivateFieldGet(this, _TitleSwitcher_titles, 'f')
|
|
193
149
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
*
|
|
197
|
-
* @return {HTMLElement|null}
|
|
150
|
+
/**
|
|
151
|
+
* Retrieve typeSurface used
|
|
152
|
+
* @return {HTMLElement|null}
|
|
198
153
|
*/
|
|
199
154
|
}, {
|
|
200
155
|
key: 'typeSurface',
|
|
201
156
|
get: function get () {
|
|
202
|
-
return
|
|
157
|
+
return __classPrivateFieldGet(this, _TitleSwitcher_typeSurface, 'f')
|
|
203
158
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
*
|
|
207
|
-
* @param {
|
|
208
|
-
* @param {number} [settings.
|
|
209
|
-
* @param {
|
|
210
|
-
* @param {boolean} [settings.
|
|
211
|
-
* @
|
|
212
|
-
* @returns {TitleSwitcher}
|
|
159
|
+
/**
|
|
160
|
+
* This is the function to begin the switching titles
|
|
161
|
+
* @param {Object} [settings={}]
|
|
162
|
+
* @param {number} [settings.delaySwitch=400]
|
|
163
|
+
* @param {number} [settings.delayEffect=200]
|
|
164
|
+
* @param {boolean} [settings.isRandom=false]
|
|
165
|
+
* @param {boolean} [settings.immediatePause=false]
|
|
166
|
+
* @returns {TitleSwitcher}
|
|
213
167
|
*/
|
|
214
168
|
}, {
|
|
215
169
|
key: 'startTitles',
|
|
@@ -224,73 +178,72 @@ var TitleSwitcher = /* #__PURE__ */(function () {
|
|
|
224
178
|
var _ref$immediatePause = _ref.immediatePause
|
|
225
179
|
var immediatePause = _ref$immediatePause === void 0 ? false : _ref$immediatePause
|
|
226
180
|
var typeSurface = 'typeSurface'
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if (
|
|
232
|
-
|
|
233
|
-
console.warn("No titles found for '".concat(
|
|
181
|
+
__classPrivateFieldSet(this, _TitleSwitcher_delaySwitch, delaySwitch, 'f')
|
|
182
|
+
__classPrivateFieldSet(this, _TitleSwitcher_delayEffect, delayEffect, 'f')
|
|
183
|
+
__classPrivateFieldSet(this, _TitleSwitcher_isRandom, isRandom, 'f')
|
|
184
|
+
__classPrivateFieldSet(this, _TitleSwitcher_active, !immediatePause, 'f')
|
|
185
|
+
if (__classPrivateFieldGet(this, _TitleSwitcher_currentIndex, 'f') >= __classPrivateFieldGet(this, _TitleSwitcher_titles, 'f').length) {
|
|
186
|
+
__classPrivateFieldSet(this, _TitleSwitcher_active, false, 'f')
|
|
187
|
+
console.warn("No titles found for '".concat(__classPrivateFieldGet(this, _TitleSwitcher_titlesContainer, 'f'), "'"))
|
|
234
188
|
return this
|
|
235
189
|
}
|
|
236
|
-
if (
|
|
237
|
-
|
|
190
|
+
if (__classPrivateFieldGet(this, _TitleSwitcher_isRandom, 'f')) {
|
|
191
|
+
__classPrivateFieldSet(this, _TitleSwitcher_currentIndex, Math.round(Math.random() * (__classPrivateFieldGet(this, _TitleSwitcher_titles, 'f').length - 2)) + 1, 'f')
|
|
238
192
|
}
|
|
239
|
-
var currentTitle =
|
|
193
|
+
var currentTitle = __classPrivateFieldGet(this, _TitleSwitcher_titles, 'f')[__classPrivateFieldGet(this, _TitleSwitcher_currentIndex, 'f')]
|
|
240
194
|
if (currentTitle.classList) {
|
|
241
|
-
currentTitle.classList.add(
|
|
195
|
+
currentTitle.classList.add(__classPrivateFieldGet(this, _TitleSwitcher_currentClass, 'f'))
|
|
242
196
|
} else {
|
|
243
|
-
currentTitle.className += ' ' +
|
|
197
|
+
currentTitle.className += ' ' + __classPrivateFieldGet(this, _TitleSwitcher_currentClass, 'f')
|
|
244
198
|
}
|
|
245
|
-
|
|
199
|
+
// @ts-ignore The Node returned is of type Element, or it should be
|
|
200
|
+
var typeElement = __classPrivateFieldGet(this, _TitleSwitcher_titles, 'f')[0].cloneNode(true)
|
|
246
201
|
if (typeElement.classList) {
|
|
247
202
|
typeElement.classList.add(typeSurface)
|
|
248
203
|
} else {
|
|
249
204
|
typeElement.className += ' ' + typeSurface
|
|
250
205
|
}
|
|
251
206
|
if (typeElement.classList) {
|
|
252
|
-
typeElement.classList.remove(
|
|
207
|
+
typeElement.classList.remove(__classPrivateFieldGet(this, _TitleSwitcher_currentClass, 'f'))
|
|
253
208
|
} else {
|
|
254
209
|
typeElement.className = typeElement.className.replace(new RegExp('(^|\\b)' + typeElement.className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ')
|
|
255
210
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
211
|
+
__classPrivateFieldGet(this, _TitleSwitcher_titlesContainer, 'f').insertBefore(typeElement, __classPrivateFieldGet(this, _TitleSwitcher_titlesContainer, 'f').firstChild)
|
|
212
|
+
// @ts-ignore the returned Node is a type of HTMLElement
|
|
213
|
+
__classPrivateFieldSet(this, _TitleSwitcher_typeSurface, __classPrivateFieldGet(this, _TitleSwitcher_titlesContainer, 'f').querySelectorAll('.' + typeSurface)[0], 'f')
|
|
214
|
+
__classPrivateFieldGet(this, _TitleSwitcher_typeSurface, 'f').innerHTML = ''
|
|
215
|
+
__classPrivateFieldGet(this, _TitleSwitcher_typeSurface, 'f').style.display = 'block'
|
|
216
|
+
Array.prototype.forEach.call(__classPrivateFieldGet(this, _TitleSwitcher_titles, 'f'), function (title) {
|
|
261
217
|
title.style.display = 'none'
|
|
262
218
|
})
|
|
263
|
-
return this.switchTitle(
|
|
219
|
+
return this.switchTitle(__classPrivateFieldGet(this, _TitleSwitcher_titles, 'f')[__classPrivateFieldGet(this, _TitleSwitcher_currentIndex, 'f')], __classPrivateFieldGet(this, _TitleSwitcher_switchStyle, 'f'), this)
|
|
264
220
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
* This is the function to pause between switching
|
|
221
|
+
/**
|
|
222
|
+
* This is the function to pause between switching
|
|
268
223
|
*/
|
|
269
224
|
}, {
|
|
270
225
|
key: 'pause',
|
|
271
226
|
value: function pause () {
|
|
272
|
-
|
|
227
|
+
__classPrivateFieldSet(this, _TitleSwitcher_active, false, 'f')
|
|
273
228
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
* This is the function to resume after a pause.
|
|
229
|
+
/**
|
|
230
|
+
* This is the function to resume after a pause.
|
|
277
231
|
*/
|
|
278
232
|
}, {
|
|
279
233
|
key: 'resume',
|
|
280
234
|
value: function resume () {
|
|
281
|
-
if (!
|
|
282
|
-
|
|
283
|
-
this.switchTitle(
|
|
235
|
+
if (!__classPrivateFieldGet(this, _TitleSwitcher_active, 'f')) {
|
|
236
|
+
__classPrivateFieldSet(this, _TitleSwitcher_active, true, 'f')
|
|
237
|
+
this.switchTitle(__classPrivateFieldGet(this, _TitleSwitcher_titles, 'f')[__classPrivateFieldGet(this, _TitleSwitcher_currentIndex, 'f')], __classPrivateFieldGet(this, _TitleSwitcher_switchStyle, 'f'), this)
|
|
284
238
|
}
|
|
285
239
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
*
|
|
289
|
-
* @param {
|
|
290
|
-
* @param {
|
|
291
|
-
* @param {
|
|
292
|
-
* @
|
|
293
|
-
* @returns {TitleSwitcher}
|
|
240
|
+
/**
|
|
241
|
+
* This is the core function for switching titles
|
|
242
|
+
* @param {HTMLElement} currentTitle
|
|
243
|
+
* @param {Function} callBackFunction
|
|
244
|
+
* @param {TitleSwitcher} self
|
|
245
|
+
* @param {boolean} [runOnce=false]
|
|
246
|
+
* @returns {TitleSwitcher}
|
|
294
247
|
*/
|
|
295
248
|
}, {
|
|
296
249
|
key: 'switchTitle',
|
|
@@ -298,23 +251,25 @@ var TitleSwitcher = /* #__PURE__ */(function () {
|
|
|
298
251
|
var runOnce = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false
|
|
299
252
|
self = self || this
|
|
300
253
|
var currentIndex = 1
|
|
301
|
-
var size =
|
|
254
|
+
var size = __classPrivateFieldGet(self, _TitleSwitcher_titles, 'f').length
|
|
302
255
|
for (var i = 1; i < size; ++i) {
|
|
303
|
-
if (
|
|
256
|
+
if (__classPrivateFieldGet(self, _TitleSwitcher_titles, 'f')[i] === currentTitle) {
|
|
304
257
|
currentIndex = i
|
|
305
258
|
break
|
|
306
259
|
}
|
|
307
260
|
}
|
|
308
|
-
if (!
|
|
309
|
-
|
|
261
|
+
if (!__classPrivateFieldGet(self, _TitleSwitcher_active, 'f')) {
|
|
262
|
+
__classPrivateFieldSet(self, _TitleSwitcher_currentIndex, currentIndex, 'f')
|
|
310
263
|
return self
|
|
311
264
|
}
|
|
312
|
-
var maxIndex =
|
|
265
|
+
var maxIndex = __classPrivateFieldGet(self, _TitleSwitcher_titles, 'f').length - 1
|
|
313
266
|
var nextIndex = 1
|
|
314
267
|
if (maxIndex === 1) {
|
|
315
|
-
return callBackFunction(currentTitle,
|
|
268
|
+
return callBackFunction(currentTitle, runOnce ? function () {
|
|
269
|
+
return self
|
|
270
|
+
} : self.switchTitle, self, runOnce)
|
|
316
271
|
}
|
|
317
|
-
if (
|
|
272
|
+
if (__classPrivateFieldGet(self, _TitleSwitcher_isRandom, 'f')) {
|
|
318
273
|
if (!self.typeSurface.textContent.trim()) {
|
|
319
274
|
currentIndex = -1
|
|
320
275
|
}
|
|
@@ -327,7 +282,7 @@ var TitleSwitcher = /* #__PURE__ */(function () {
|
|
|
327
282
|
}
|
|
328
283
|
nextIndex = currentIndex < maxIndex ? currentIndex + 1 : 1
|
|
329
284
|
}
|
|
330
|
-
var nextTitle =
|
|
285
|
+
var nextTitle = __classPrivateFieldGet(self, _TitleSwitcher_titles, 'f')[nextIndex]
|
|
331
286
|
if (currentTitle.classList) {
|
|
332
287
|
currentTitle.classList.remove(self.currentClass)
|
|
333
288
|
} else {
|
|
@@ -339,17 +294,18 @@ var TitleSwitcher = /* #__PURE__ */(function () {
|
|
|
339
294
|
nextTitle.className += ' ' + self.currentClass
|
|
340
295
|
}
|
|
341
296
|
return callBackFunction(nextTitle, runOnce ? function () {
|
|
342
|
-
return
|
|
297
|
+
return self
|
|
343
298
|
} : self.switchTitle, self, runOnce)
|
|
344
299
|
}
|
|
345
300
|
}])
|
|
346
301
|
return TitleSwitcher
|
|
347
302
|
}())
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
*
|
|
351
|
-
* @param {
|
|
352
|
-
* @
|
|
303
|
+
_TitleSwitcher_active = new WeakMap(), _TitleSwitcher_currentClass = new WeakMap(), _TitleSwitcher_currentIndex = new WeakMap(), _TitleSwitcher_delayEffect = new WeakMap(), _TitleSwitcher_delaySwitch = new WeakMap(), _TitleSwitcher_isRandom = new WeakMap(), _TitleSwitcher_titles = new WeakMap(), _TitleSwitcher_titlesContainer = new WeakMap(), _TitleSwitcher_switchStyle = new WeakMap(), _TitleSwitcher_typeSurface = new WeakMap()
|
|
304
|
+
/**
|
|
305
|
+
* This is a helper function to improve the default 'typingEffect'
|
|
306
|
+
* @param {boolean} blinkOn
|
|
307
|
+
* @param {TitleSwitcher} self
|
|
308
|
+
* @return {TitleSwitcher}
|
|
353
309
|
*/
|
|
354
310
|
TitleSwitcher.prototype.cursorBlink = function (blinkOn, self) {
|
|
355
311
|
// display cursor effect
|
|
@@ -362,16 +318,15 @@ TitleSwitcher.prototype.cursorBlink = function (blinkOn, self) {
|
|
|
362
318
|
}
|
|
363
319
|
return self
|
|
364
320
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
* @param {
|
|
371
|
-
* @param {
|
|
372
|
-
* @param {
|
|
373
|
-
* @
|
|
374
|
-
* @returns {TitleSwitcher}
|
|
321
|
+
/**
|
|
322
|
+
* This is the default and example of an effect being implemented when Titles are switched
|
|
323
|
+
* These functions take the currentElement in focus, the switchTitle function as a callback
|
|
324
|
+
* and an instance of the TitleSwitcher
|
|
325
|
+
* @param {HTMLElement} domObject
|
|
326
|
+
* @param {Function} callBackFunction
|
|
327
|
+
* @param {TitleSwitcher} self
|
|
328
|
+
* @param {boolean} [runOnce=false]
|
|
329
|
+
* @returns {TitleSwitcher}
|
|
375
330
|
*/
|
|
376
331
|
TitleSwitcher.prototype.typingEffect = function (domObject, callBackFunction, self) {
|
|
377
332
|
var runOnce = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false
|
|
@@ -385,7 +340,6 @@ TitleSwitcher.prototype.typingEffect = function (domObject, callBackFunction, se
|
|
|
385
340
|
}
|
|
386
341
|
}
|
|
387
342
|
domObject = domObject || self.titles[currentIndex + 1]
|
|
388
|
-
callBackFunction = callBackFunction || self.switchStyle
|
|
389
343
|
var blinkOn = true
|
|
390
344
|
var numBlinks = 4
|
|
391
345
|
if (self.typeSurface.hasAttribute('style')) {
|
|
@@ -397,7 +351,6 @@ TitleSwitcher.prototype.typingEffect = function (domObject, callBackFunction, se
|
|
|
397
351
|
// If we copied the title style, then display:none is set, so we need to ensure the surface is display:block
|
|
398
352
|
self.typeSurface.innerHTML = ''
|
|
399
353
|
self.typeSurface.style.display = 'block'
|
|
400
|
-
|
|
401
354
|
// Initialize with a few cursor blinks
|
|
402
355
|
for (var _i = 0; _i < numBlinks; ++_i) {
|
|
403
356
|
setTimeout(function () {
|
|
@@ -425,7 +378,7 @@ TitleSwitcher.prototype.typingEffect = function (domObject, callBackFunction, se
|
|
|
425
378
|
self.cursorBlink(blinkOn, self)
|
|
426
379
|
if (_j === 0) {
|
|
427
380
|
callBackFunction(domObject, function () {
|
|
428
|
-
return
|
|
381
|
+
return self
|
|
429
382
|
}, self, runOnce)
|
|
430
383
|
// callBackFunction(domObject, runOnce ? () => null : self.switchStyle, self, runOnce)
|
|
431
384
|
}
|
|
@@ -441,9 +394,11 @@ TitleSwitcher.prototype.typingEffect = function (domObject, callBackFunction, se
|
|
|
441
394
|
}, numBlinks * self.delaySwitch)
|
|
442
395
|
return self
|
|
443
396
|
}
|
|
444
|
-
|
|
397
|
+
exports.default = TitleSwitcher
|
|
445
398
|
if (void 0) {
|
|
399
|
+
// @ts-ignore 'this' is used in node as the global, and the key CAN be referenced by string
|
|
446
400
|
(void 0).TitleSwitcher = TitleSwitcher
|
|
447
401
|
} else if (typeof window !== 'undefined') {
|
|
402
|
+
// @ts-ignore YES, we can use a string to add a property to Window
|
|
448
403
|
window.TitleSwitcher = TitleSwitcher
|
|
449
404
|
}
|