reveal.js-appearance 1.0.9 → 1.1.2

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.
@@ -4,7 +4,7 @@
4
4
  * https://github.com/Martinomagnifico
5
5
  *
6
6
  * Appearance.js for Reveal.js
7
- * Version 1.0.9
7
+ * Version 1.1.2
8
8
  *
9
9
  * @license
10
10
  * MIT licensed
@@ -15,6 +15,65 @@
15
15
  ******************************************************************/
16
16
 
17
17
 
18
+ function _slicedToArray(arr, i) {
19
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
20
+ }
21
+
22
+ function _arrayWithHoles(arr) {
23
+ if (Array.isArray(arr)) return arr;
24
+ }
25
+
26
+ function _iterableToArrayLimit(arr, i) {
27
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
28
+
29
+ if (_i == null) return;
30
+ var _arr = [];
31
+ var _n = true;
32
+ var _d = false;
33
+
34
+ var _s, _e;
35
+
36
+ try {
37
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
38
+ _arr.push(_s.value);
39
+
40
+ if (i && _arr.length === i) break;
41
+ }
42
+ } catch (err) {
43
+ _d = true;
44
+ _e = err;
45
+ } finally {
46
+ try {
47
+ if (!_n && _i["return"] != null) _i["return"]();
48
+ } finally {
49
+ if (_d) throw _e;
50
+ }
51
+ }
52
+
53
+ return _arr;
54
+ }
55
+
56
+ function _unsupportedIterableToArray(o, minLen) {
57
+ if (!o) return;
58
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
59
+ var n = Object.prototype.toString.call(o).slice(8, -1);
60
+ if (n === "Object" && o.constructor) n = o.constructor.name;
61
+ if (n === "Map" || n === "Set") return Array.from(o);
62
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
63
+ }
64
+
65
+ function _arrayLikeToArray(arr, len) {
66
+ if (len == null || len > arr.length) len = arr.length;
67
+
68
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
69
+
70
+ return arr2;
71
+ }
72
+
73
+ function _nonIterableRest() {
74
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
75
+ }
76
+
18
77
  var Plugin = function Plugin() {
19
78
  // Scope support polyfill
20
79
  try {
@@ -66,54 +125,130 @@ var Plugin = function Plugin() {
66
125
  }(Element.prototype);
67
126
  }
68
127
 
128
+ var loadStyle = function loadStyle(url, type, callback) {
129
+ var head = document.querySelector('head');
130
+ var style;
131
+ style = document.createElement('link');
132
+ style.rel = 'stylesheet';
133
+ style.href = url;
134
+
135
+ var finish = function finish() {
136
+ if (typeof callback === 'function') {
137
+ callback.call();
138
+ callback = null;
139
+ }
140
+ };
141
+
142
+ style.onload = finish;
143
+
144
+ style.onreadystatechange = function () {
145
+ if (this.readyState === 'loaded') {
146
+ finish();
147
+ }
148
+ };
149
+
150
+ head.appendChild(style);
151
+ };
152
+
153
+ var selectionArray = function selectionArray(container, selectors) {
154
+ var selections = container.querySelectorAll(selectors);
155
+ var selectionarray = Array.prototype.slice.call(selections);
156
+ return selectionarray;
157
+ };
158
+
69
159
  var appear = function appear(deck, options) {
160
+ var baseclass = 'animate__animated';
161
+ var appearanceSelector = options.compatibility ? ".".concat(options.compatibilitybaseclass) : ".".concat(baseclass);
162
+ var fragmentSelector = ".fragment";
163
+ var sections = deck.getRevealElement().querySelectorAll(".slides section");
164
+ var fragments = deck.getRevealElement().querySelectorAll(fragmentSelector);
165
+ var animatecss = '[class^="animate__"],[class*=" animate__"]';
166
+
70
167
  var debugLog = function debugLog(text) {
71
168
  if (options.debug) console.log(text);
72
169
  };
73
170
 
74
- var timeouts = [];
75
-
76
- var clearTimeOuts = function clearTimeOuts(timeouts) {
77
- for (var i = 0; i < timeouts.length; i++) {
78
- clearTimeout(timeouts[i]);
171
+ var findAppearancesIn = function findAppearancesIn(container, includeClass, excludeClass) {
172
+ if (!isStack(container)) {
173
+ var appearances = selectionArray(container, ":scope ".concat(includeClass));
174
+ var excludes = selectionArray(container, ":scope ".concat(excludeClass, " ").concat(includeClass));
175
+ var delay = 0;
176
+ appearances.filter(function (appearance, index) {
177
+ if (!(excludes.indexOf(appearance) > -1)) {
178
+ if (index == 0 && appearance.dataset.delay || index != 0) {
179
+ var elementDelay = appearance.dataset.delay ? parseInt(appearance.dataset.delay) : options.delay;
180
+ delay = delay + elementDelay;
181
+ appearance.style.setProperty('animation-delay', delay + "ms");
182
+ }
183
+ }
184
+ });
79
185
  }
80
-
81
- timeouts = [];
82
186
  };
83
187
 
84
- var loopAppearances = function loopAppearances(appearances, appearancesInFragment) {
85
- var delay = 0;
86
- appearances.filter(function (element, i) {
87
- if (!(appearancesInFragment.indexOf(element) > -1)) {
88
- var delayincrement = parseInt(element.dataset.delay ? element.dataset.delay : i > 0 ? options.delay : 0);
89
- delay += delayincrement;
90
- timeouts.push(setTimeout(function () {
91
- element.classList.add(options.visibleclass);
92
- }, delay));
188
+ var autoAdd = function autoAdd() {
189
+ if (options.autoelements) {
190
+ var _loop = function _loop() {
191
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
192
+ autoelement = _Object$entries$_i[0],
193
+ autoanimation = _Object$entries$_i[1];
194
+
195
+ if (options.autoappear) {
196
+ debugLog("All \"".concat(autoelement, "\"\" elements will animate with ").concat(autoanimation));
197
+ }
198
+
199
+ var autosection = options.autoappear ? "" : "[data-autoappear] ";
200
+ var autoAppearances = deck.getRevealElement().querySelectorAll(".slides ".concat(autosection).concat(autoelement));
201
+
202
+ if (autoAppearances.length > 0) {
203
+ autoAppearances.forEach(function (autoAppearance) {
204
+ if (!autoAppearance.classList.contains(baseclass)) {
205
+ autoAppearance.classList.add(baseclass);
206
+ autoAppearance.classList.add(autoanimation);
207
+ }
208
+ });
209
+ }
210
+ };
211
+
212
+ for (var _i = 0, _Object$entries = Object.entries(options.autoelements); _i < _Object$entries.length; _i++) {
213
+ _loop();
93
214
  }
94
- });
215
+ } else if (options.autoappear) {
216
+ console.log("Please set an \"autoelements\" object.");
217
+ }
95
218
  };
96
219
 
97
- var selectionArray = function selectionArray(container, selectors) {
98
- var selections = container.querySelectorAll(selectors);
99
- var selectionarray = Array.prototype.slice.call(selections);
100
- return selectionarray;
101
- };
220
+ var isStack = function isStack(section) {
221
+ var isStack = false;
102
222
 
103
- var showAppearances = function showAppearances(container) {
104
- clearTimeOuts(timeouts);
105
- var appearances = selectionArray(container, ":scope ." + options.baseclass);
106
- var appearancesInFragment = selectionArray(container, ":scope .fragment .".concat(options.baseclass));
107
- loopAppearances(appearances, appearancesInFragment);
108
- };
223
+ for (var i = 0; i < section.childNodes.length; i++) {
224
+ if (section.childNodes[i].tagName == "SECTION") {
225
+ isStack = true;
226
+ break;
227
+ }
228
+ }
109
229
 
110
- var hideAppearances = function hideAppearances(container) {
111
- var disappearances = selectionArray(container, ":scope .".concat(options.baseclass, ", :scope .fragment.visible"));
112
- disappearances.filter(function (element) {
113
- element.classList.remove(element.classList.contains("fragment") ? "visible" : options.visibleclass);
114
- });
230
+ return isStack;
115
231
  };
116
232
 
233
+ if (options.compatibility) {
234
+ animatecss = '.backInDown, .backInLeft, .backInRight, .backInUp, .bounceIn, .bounceInDown, .bounceInLeft, .bounceInRight, .bounceInUp, .fadeIn, .fadeInDown, .fadeInDownBig, .fadeInLeft, .fadeInLeftBig, .fadeInRight, .fadeInRightBig, .fadeInUp, .fadeInUpBig, .fadeInTopLeft, .fadeInTopRight, .fadeInBottomLeft, .fadeInBottomRight, .flipInX, .flipInY, .lightSpeedInRight, .lightSpeedInLeft, .rotateIn, .rotateInDownLeft, .rotateInDownRight, .rotateInUpLeft, .rotateInUpRight, .jackInTheBox, .rollIn, .zoomIn, .zoomInDown, .zoomInLeft, .zoomInRight, .zoomInUp, .slideInDown, .slideInLeft, .slideInRight, .slideInUp, .skidLeft, .skidLeftBig, .skidRight, .skidRightBig, .shrinkIn, .shrinkInBlur';
235
+ baseclass = options.compatibilitybaseclass;
236
+ }
237
+
238
+ var allappearances = deck.getRevealElement().querySelectorAll(animatecss);
239
+ allappearances.forEach(function (appearance) {
240
+ if (!appearance.classList.contains(baseclass)) {
241
+ appearance.classList.add(baseclass);
242
+ }
243
+ });
244
+ autoAdd();
245
+ sections.forEach(function (section) {
246
+ findAppearancesIn(section, appearanceSelector, fragmentSelector);
247
+ });
248
+ fragments.forEach(function (fragment) {
249
+ findAppearancesIn(fragment, appearanceSelector, fragmentSelector);
250
+ });
251
+
117
252
  var fromTo = function fromTo(event) {
118
253
  var slides = {};
119
254
  slides.from = event.fromSlide ? event.fromSlide : event.previousSlide ? event.previousSlide : null;
@@ -122,9 +257,13 @@ var Plugin = function Plugin() {
122
257
  };
123
258
 
124
259
  var showHideSlide = function showHideSlide(event) {
260
+ var _slides$to;
261
+
262
+ var etype = event.type;
125
263
  var slides = fromTo(event);
264
+ debugLog(etype);
126
265
 
127
- if (slides.to.dataset.appearevent == "auto") {
266
+ if (((_slides$to = slides.to) === null || _slides$to === void 0 ? void 0 : _slides$to.dataset.appearevent) == "auto") {
128
267
  slides.to.dataset.appearevent = "autoanimate";
129
268
  }
130
269
 
@@ -132,27 +271,37 @@ var Plugin = function Plugin() {
132
271
  options.appearevent = "autoanimate";
133
272
  }
134
273
 
135
- if (!slides.to.dataset.eventdone) {
136
- debugLog("Event: '".concat(event.type, "'"));
137
-
138
- if (event.type == "ready") {
139
- showAppearances(slides.to);
140
- } else if (event.type == slides.to.dataset.appearevent) {
141
- slides.to.dataset.eventdone = true;
142
- showAppearances(slides.to);
143
- } else if (event.type == options.appearevent) {
144
- slides.to.dataset.eventdone = true;
145
- showAppearances(slides.to);
146
- } else if (event.type == "slidetransitionend" && options.appearevent == "autoanimate") {
147
- slides.to.dataset.eventdone = true;
148
- showAppearances(slides.to);
149
- } else if (event.type == 'slidechanged' && document.body.dataset.exitoverview) {
150
- if (slides.from && options.hideagain) {
151
- hideAppearances(slides.to);
274
+ if (etype == "ready") {
275
+ slides.to.dataset.appearanceCanStart = true;
276
+ }
277
+
278
+ if (slides.to) {
279
+ var appearevent = slides.to.dataset.appearevent ? slides.to.dataset.appearevent : options.appearevent;
280
+
281
+ if (etype == appearevent || etype == "slidetransitionend" && appearevent == "autoanimate") {
282
+ slides.to.dataset.appearanceCanStart = true;
283
+ }
284
+
285
+ if (etype == "slidetransitionend") {
286
+ if (options.hideagain) {
287
+ var _slides$from;
288
+
289
+ (_slides$from = slides.from) === null || _slides$from === void 0 ? true : delete _slides$from.dataset.appearanceCanStart;
290
+ var fromFragments = slides.from.querySelectorAll(".fragment.visible");
291
+ fromFragments.forEach(function (fragment) {
292
+ fragment.classList.remove('visible');
293
+ });
294
+ }
295
+ }
296
+
297
+ if (event.type == 'slidechanged' && document.body.dataset.exitoverview) {
298
+ if (options.hideagain) {
299
+ var _slides$from2;
300
+
301
+ (_slides$from2 = slides.from) === null || _slides$from2 === void 0 ? true : delete _slides$from2.dataset.appearanceCanStart;
152
302
  }
153
303
 
154
- showAppearances(slides.to);
155
- slides.to.dataset.eventdone = true;
304
+ slides.to.dataset.appearanceCanStart = true;
156
305
  } else if (event.type == 'overviewhidden') {
157
306
  document.body.dataset.exitoverview = true;
158
307
  setTimeout(function () {
@@ -160,66 +309,43 @@ var Plugin = function Plugin() {
160
309
  }, 500);
161
310
 
162
311
  if (event.currentSlide) {
163
- if (slides.from && options.hideagain) {
164
- hideAppearances(event.previousSlide);
312
+ if (options.hideagain) {
313
+ var _slides$from3;
314
+
315
+ (_slides$from3 = slides.from) === null || _slides$from3 === void 0 ? true : delete _slides$from3.dataset.appearanceCanStart;
165
316
  }
166
317
 
167
- showAppearances(slides.to);
168
- event.currentSlide.dataset.eventdone = true;
318
+ slides.to.dataset.appearanceCanStart = true;
169
319
  }
170
320
  }
171
321
  }
172
-
173
- if (event.type == "slidechanged" && slides.from) {
174
- slides.from.removeAttribute('data-eventdone');
175
- }
176
-
177
- if (slides.from) {
178
- if (event.type == 'slidetransitionend' && options.hideagain) {
179
- hideAppearances(slides.from);
180
- }
181
- }
182
- };
183
-
184
- var showHideFragment = function showHideFragment(event) {
185
- if (event.type == "fragmentshowncomplete" || event.type == "fragmentshown") {
186
- showAppearances(event.fragment);
187
- } else {
188
- hideAppearances(event.fragment);
189
- }
190
322
  };
191
323
 
192
- deck.on('ready', function (event) {
193
- showHideSlide(event);
194
- });
195
- deck.on('slidechanged', function (event) {
196
- showHideSlide(event);
197
- });
198
- deck.on('slidetransitionend', function (event) {
199
- showHideSlide(event);
200
- });
201
- deck.on('autoanimate', function (event) {
202
- showHideSlide(event);
203
- });
204
- deck.on('overviewhidden', function (event) {
205
- showHideSlide(event);
206
- });
207
- deck.on('fragmentshown', function (event) {
208
- showHideFragment(event);
209
- });
210
- deck.on('fragmenthidden', function (event) {
211
- showHideFragment(event);
324
+ var eventnames = ['ready', 'slidechanged', 'slidetransitionend', 'autoanimate', 'overviewhidden'];
325
+ eventnames.forEach(function (eventname) {
326
+ return deck.on(eventname, function (event) {
327
+ showHideSlide(event);
328
+ });
212
329
  });
213
330
  };
214
331
 
215
332
  var init = function init(deck) {
333
+ var es5Filename = "appearance.js";
216
334
  var defaultOptions = {
217
- baseclass: 'animated',
218
- visibleclass: 'in',
335
+ baseclass: 'animate__animated',
219
336
  hideagain: true,
220
337
  delay: 300,
221
338
  debug: false,
222
- appearevent: 'slidetransitionend'
339
+ appearevent: 'slidetransitionend',
340
+ autoappear: false,
341
+ autoelements: false,
342
+ csspath: '',
343
+ animatecsspath: {
344
+ link: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css',
345
+ compat: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.0.0/animate.compat.css'
346
+ },
347
+ compatibility: false,
348
+ compatibilitybaseclass: 'animated'
223
349
  };
224
350
 
225
351
  var defaults = function defaults(options, defaultOptions) {
@@ -232,6 +358,33 @@ var Plugin = function Plugin() {
232
358
 
233
359
  var options = deck.getConfig().appearance || {};
234
360
  defaults(options, defaultOptions);
361
+
362
+ function pluginPath() {
363
+ var path;
364
+ var pluginScript = document.querySelector("script[src$=\"".concat(es5Filename, "\"]"));
365
+
366
+ if (pluginScript) {
367
+ path = pluginScript.getAttribute("src").slice(0, -1 * es5Filename.length);
368
+ } else {
369
+ path = import.meta.url.slice(0, import.meta.url.lastIndexOf('/') + 1);
370
+ }
371
+
372
+ return path;
373
+ }
374
+
375
+ var AppearanceStylePath = options.csspath.appearance ? options.csspath.appearance : "".concat(pluginPath(), "appearance.css") || 'plugin/appearance/appearance.css';
376
+ var AnimateCSSPath = !options.compatibility ? options.animatecsspath.link : options.animatecsspath.compat;
377
+
378
+ if (options.debug) {
379
+ console.log("Plugin path = ".concat(pluginPath()));
380
+ console.log("Compatibility mode: ".concat(options.compatibility));
381
+ console.log("Appearance CSS path = ".concat(AppearanceStylePath));
382
+ console.log("AnimateCSS CSS path = ".concat(AnimateCSSPath));
383
+ }
384
+
385
+ loadStyle(AnimateCSSPath, 'stylesheet', function () {
386
+ loadStyle(AppearanceStylePath, 'stylesheet');
387
+ });
235
388
  appear(deck, options);
236
389
  };
237
390
 
@@ -241,4 +394,4 @@ var Plugin = function Plugin() {
241
394
  };
242
395
  };
243
396
 
244
- export default Plugin;
397
+ export { Plugin as default };