reveal.js-appearance 1.1.1 → 1.1.3

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.1.1
7
+ * Version 1.1.3
8
8
  *
9
9
  * @license
10
10
  * MIT licensed
@@ -18,8 +18,8 @@
18
18
  (function (global, factory) {
19
19
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
20
20
  typeof define === 'function' && define.amd ? define(factory) :
21
- (global = global || self, global.Appearance = factory());
22
- }(this, (function () { 'use strict';
21
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Appearance = factory());
22
+ })(this, (function () { 'use strict';
23
23
 
24
24
  function _slicedToArray(arr, i) {
25
25
  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
@@ -30,14 +30,17 @@
30
30
  }
31
31
 
32
32
  function _iterableToArrayLimit(arr, i) {
33
- if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
33
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
34
+
35
+ if (_i == null) return;
34
36
  var _arr = [];
35
37
  var _n = true;
36
38
  var _d = false;
37
- var _e = undefined;
39
+
40
+ var _s, _e;
38
41
 
39
42
  try {
40
- for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
43
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
41
44
  _arr.push(_s.value);
42
45
 
43
46
  if (i && _arr.length === i) break;
@@ -128,38 +131,64 @@
128
131
  }(Element.prototype);
129
132
  }
130
133
 
131
- var appear = function appear(deck, options) {
132
- var debugLog = function debugLog(text) {
133
- if (options.debug) console.log(text);
134
+ var loadStyle = function loadStyle(url, type, callback) {
135
+ var head = document.querySelector('head');
136
+ var style;
137
+ style = document.createElement('link');
138
+ style.rel = 'stylesheet';
139
+ style.href = url;
140
+
141
+ var finish = function finish() {
142
+ if (typeof callback === 'function') {
143
+ callback.call();
144
+ callback = null;
145
+ }
134
146
  };
135
147
 
136
- var timeouts = [];
148
+ style.onload = finish;
137
149
 
138
- var clearTimeOuts = function clearTimeOuts(timeouts) {
139
- for (var i = 0; i < timeouts.length; i++) {
140
- clearTimeout(timeouts[i]);
150
+ style.onreadystatechange = function () {
151
+ if (this.readyState === 'loaded') {
152
+ finish();
141
153
  }
142
-
143
- timeouts = [];
144
154
  };
145
155
 
146
- var loopAppearances = function loopAppearances(appearances, appearancesInFragment) {
147
- var delay = 0;
148
- appearances.filter(function (element, i) {
149
- if (!(appearancesInFragment.indexOf(element) > -1)) {
150
- var delayincrement = parseInt(element.dataset.delay ? element.dataset.delay : i > 0 ? options.delay : 0);
151
- delay += delayincrement;
152
- timeouts.push(setTimeout(function () {
153
- element.classList.add(options.visibleclass);
154
- }, delay));
155
- }
156
- });
156
+ head.appendChild(style);
157
+ };
158
+
159
+ var selectionArray = function selectionArray(container, selectors) {
160
+ var selections = container.querySelectorAll(selectors);
161
+ var selectionarray = Array.prototype.slice.call(selections);
162
+ return selectionarray;
163
+ };
164
+
165
+ var appear = function appear(deck, options) {
166
+ var baseclass = 'animate__animated';
167
+ var appearanceSelector = options.compatibility ? ".".concat(options.compatibilitybaseclass) : ".".concat(baseclass);
168
+ var fragmentSelector = ".fragment";
169
+ var sections = deck.getRevealElement().querySelectorAll(".slides section");
170
+ var fragments = deck.getRevealElement().querySelectorAll(fragmentSelector);
171
+ var animatecss = '[class^="animate__"],[class*=" animate__"]';
172
+
173
+ var debugLog = function debugLog(text) {
174
+ if (options.debug) console.log(text);
157
175
  };
158
176
 
159
- var selectionArray = function selectionArray(container, selectors) {
160
- var selections = container.querySelectorAll(selectors);
161
- var selectionarray = Array.prototype.slice.call(selections);
162
- return selectionarray;
177
+ var findAppearancesIn = function findAppearancesIn(container, includeClass, excludeClass) {
178
+ if (!isStack(container)) {
179
+ var appearances = selectionArray(container, ":scope ".concat(includeClass));
180
+ var excludes = selectionArray(container, ":scope ".concat(excludeClass, " ").concat(includeClass));
181
+ var delay = 0;
182
+ appearances.filter(function (appearance, index) {
183
+ if (!(excludes.indexOf(appearance) > -1)) {
184
+ if (index == 0 && appearance.dataset.delay || index != 0) {
185
+ var elementDelay = appearance.dataset.delay ? parseInt(appearance.dataset.delay) : options.delay;
186
+ delay = delay + elementDelay;
187
+ appearance.style.setProperty('animation-delay', delay + "ms");
188
+ }
189
+ }
190
+ });
191
+ }
163
192
  };
164
193
 
165
194
  var autoAdd = function autoAdd() {
@@ -178,8 +207,8 @@
178
207
 
179
208
  if (autoAppearances.length > 0) {
180
209
  autoAppearances.forEach(function (autoAppearance) {
181
- if (!autoAppearance.classList.contains(options.baseclass)) {
182
- autoAppearance.classList.add(options.baseclass);
210
+ if (!autoAppearance.classList.contains(baseclass)) {
211
+ autoAppearance.classList.add(baseclass);
183
212
  autoAppearance.classList.add(autoanimation);
184
213
  }
185
214
  });
@@ -194,20 +223,38 @@
194
223
  }
195
224
  };
196
225
 
197
- var showAppearances = function showAppearances(container) {
198
- clearTimeOuts(timeouts);
199
- var appearances = selectionArray(container, ":scope ." + options.baseclass);
200
- var appearancesInFragment = selectionArray(container, ":scope .fragment .".concat(options.baseclass));
201
- loopAppearances(appearances, appearancesInFragment);
202
- };
226
+ var isStack = function isStack(section) {
227
+ var isStack = false;
203
228
 
204
- var hideAppearances = function hideAppearances(container) {
205
- var disappearances = selectionArray(container, ":scope .".concat(options.baseclass, ", :scope .fragment.visible"));
206
- disappearances.filter(function (element) {
207
- element.classList.remove(element.classList.contains("fragment") ? "visible" : options.visibleclass);
208
- });
229
+ for (var i = 0; i < section.childNodes.length; i++) {
230
+ if (section.childNodes[i].tagName == "SECTION") {
231
+ isStack = true;
232
+ break;
233
+ }
234
+ }
235
+
236
+ return isStack;
209
237
  };
210
238
 
239
+ if (options.compatibility) {
240
+ 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';
241
+ baseclass = options.compatibilitybaseclass;
242
+ }
243
+
244
+ var allappearances = deck.getRevealElement().querySelectorAll(animatecss);
245
+ allappearances.forEach(function (appearance) {
246
+ if (!appearance.classList.contains(baseclass)) {
247
+ appearance.classList.add(baseclass);
248
+ }
249
+ });
250
+ autoAdd();
251
+ sections.forEach(function (section) {
252
+ findAppearancesIn(section, appearanceSelector, fragmentSelector);
253
+ });
254
+ fragments.forEach(function (fragment) {
255
+ findAppearancesIn(fragment, appearanceSelector, fragmentSelector);
256
+ });
257
+
211
258
  var fromTo = function fromTo(event) {
212
259
  var slides = {};
213
260
  slides.from = event.fromSlide ? event.fromSlide : event.previousSlide ? event.previousSlide : null;
@@ -216,9 +263,13 @@
216
263
  };
217
264
 
218
265
  var showHideSlide = function showHideSlide(event) {
266
+ var _slides$to;
267
+
268
+ var etype = event.type;
219
269
  var slides = fromTo(event);
270
+ debugLog(etype);
220
271
 
221
- if (slides.to.dataset.appearevent == "auto") {
272
+ if (((_slides$to = slides.to) === null || _slides$to === void 0 ? void 0 : _slides$to.dataset.appearevent) == "auto") {
222
273
  slides.to.dataset.appearevent = "autoanimate";
223
274
  }
224
275
 
@@ -226,27 +277,43 @@
226
277
  options.appearevent = "autoanimate";
227
278
  }
228
279
 
229
- if (!slides.to.dataset.eventdone) {
230
- debugLog("Event: '".concat(event.type, "'"));
231
-
232
- if (event.type == "ready") {
233
- showAppearances(slides.to);
234
- } else if (event.type == slides.to.dataset.appearevent) {
235
- slides.to.dataset.eventdone = true;
236
- showAppearances(slides.to);
237
- } else if (event.type == options.appearevent) {
238
- slides.to.dataset.eventdone = true;
239
- showAppearances(slides.to);
240
- } else if (event.type == "slidetransitionend" && options.appearevent == "autoanimate") {
241
- slides.to.dataset.eventdone = true;
242
- showAppearances(slides.to);
243
- } else if (event.type == 'slidechanged' && document.body.dataset.exitoverview) {
244
- if (slides.from && options.hideagain) {
245
- hideAppearances(slides.to);
280
+ if (etype == "ready") {
281
+ slides.to.dataset.appearanceCanStart = true;
282
+ }
283
+
284
+ if (slides.to) {
285
+ var appearevent = slides.to.dataset.appearevent ? slides.to.dataset.appearevent : options.appearevent;
286
+
287
+ if (etype == appearevent || etype == "slidetransitionend" && appearevent == "autoanimate") {
288
+ slides.to.dataset.appearanceCanStart = true;
289
+ }
290
+
291
+ if (etype == "slidetransitionend") {
292
+ if (options.hideagain) {
293
+ if (slides.from) {
294
+ if (slides.from.dataset.appearanceCanStart) {
295
+ delete slides.from.dataset.appearanceCanStart;
296
+ }
297
+
298
+ var fromFragments = slides.from.querySelectorAll(".fragment.visible");
299
+
300
+ if (fromFragments) {
301
+ fromFragments.forEach(function (fragment) {
302
+ fragment.classList.remove('visible');
303
+ });
304
+ }
305
+ }
246
306
  }
307
+ }
308
+
309
+ if (event.type == 'slidechanged' && document.body.dataset.exitoverview) {
310
+ if (options.hideagain) {
311
+ var _slides$from;
247
312
 
248
- showAppearances(slides.to);
249
- slides.to.dataset.eventdone = true;
313
+ (_slides$from = slides.from) === null || _slides$from === void 0 ? true : delete _slides$from.dataset.appearanceCanStart;
314
+ }
315
+
316
+ slides.to.dataset.appearanceCanStart = true;
250
317
  } else if (event.type == 'overviewhidden') {
251
318
  document.body.dataset.exitoverview = true;
252
319
  setTimeout(function () {
@@ -254,69 +321,43 @@
254
321
  }, 500);
255
322
 
256
323
  if (event.currentSlide) {
257
- if (slides.from && options.hideagain) {
258
- hideAppearances(event.previousSlide);
324
+ if (options.hideagain) {
325
+ var _slides$from2;
326
+
327
+ (_slides$from2 = slides.from) === null || _slides$from2 === void 0 ? true : delete _slides$from2.dataset.appearanceCanStart;
259
328
  }
260
329
 
261
- showAppearances(slides.to);
262
- event.currentSlide.dataset.eventdone = true;
330
+ slides.to.dataset.appearanceCanStart = true;
263
331
  }
264
332
  }
265
333
  }
266
-
267
- if (event.type == "slidechanged" && slides.from) {
268
- slides.from.removeAttribute('data-eventdone');
269
- }
270
-
271
- if (slides.from) {
272
- if (event.type == 'slidetransitionend' && options.hideagain) {
273
- hideAppearances(slides.from);
274
- }
275
- }
276
- };
277
-
278
- var showHideFragment = function showHideFragment(event) {
279
- if (event.type == "fragmentshowncomplete" || event.type == "fragmentshown") {
280
- showAppearances(event.fragment);
281
- } else {
282
- hideAppearances(event.fragment);
283
- }
284
334
  };
285
335
 
286
- deck.on('ready', function (event) {
287
- autoAdd();
288
- showHideSlide(event);
289
- });
290
- deck.on('slidechanged', function (event) {
291
- showHideSlide(event);
292
- });
293
- deck.on('slidetransitionend', function (event) {
294
- showHideSlide(event);
295
- });
296
- deck.on('autoanimate', function (event) {
297
- showHideSlide(event);
298
- });
299
- deck.on('overviewhidden', function (event) {
300
- showHideSlide(event);
301
- });
302
- deck.on('fragmentshown', function (event) {
303
- showHideFragment(event);
304
- });
305
- deck.on('fragmenthidden', function (event) {
306
- showHideFragment(event);
336
+ var eventnames = ['ready', 'slidechanged', 'slidetransitionend', 'autoanimate', 'overviewhidden'];
337
+ eventnames.forEach(function (eventname) {
338
+ return deck.on(eventname, function (event) {
339
+ showHideSlide(event);
340
+ });
307
341
  });
308
342
  };
309
343
 
310
344
  var init = function init(deck) {
345
+ var es5Filename = "appearance.js";
311
346
  var defaultOptions = {
312
- baseclass: 'animated',
313
- visibleclass: 'in',
347
+ baseclass: 'animate__animated',
314
348
  hideagain: true,
315
349
  delay: 300,
316
350
  debug: false,
317
351
  appearevent: 'slidetransitionend',
318
352
  autoappear: false,
319
- autoelements: null
353
+ autoelements: false,
354
+ csspath: '',
355
+ animatecsspath: {
356
+ link: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css',
357
+ compat: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.0.0/animate.compat.css'
358
+ },
359
+ compatibility: false,
360
+ compatibilitybaseclass: 'animated'
320
361
  };
321
362
 
322
363
  var defaults = function defaults(options, defaultOptions) {
@@ -329,6 +370,33 @@
329
370
 
330
371
  var options = deck.getConfig().appearance || {};
331
372
  defaults(options, defaultOptions);
373
+
374
+ function pluginPath() {
375
+ var path;
376
+ var pluginScript = document.querySelector("script[src$=\"".concat(es5Filename, "\"]"));
377
+
378
+ if (pluginScript) {
379
+ path = pluginScript.getAttribute("src").slice(0, -1 * es5Filename.length);
380
+ } else {
381
+ path = (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('appearance.js', document.baseURI).href)).slice(0, (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('appearance.js', document.baseURI).href)).lastIndexOf('/') + 1);
382
+ }
383
+
384
+ return path;
385
+ }
386
+
387
+ var AppearanceStylePath = options.csspath.appearance ? options.csspath.appearance : "".concat(pluginPath(), "appearance.css") || 'plugin/appearance/appearance.css';
388
+ var AnimateCSSPath = !options.compatibility ? options.animatecsspath.link : options.animatecsspath.compat;
389
+
390
+ if (options.debug) {
391
+ console.log("Plugin path = ".concat(pluginPath()));
392
+ console.log("Compatibility mode: ".concat(options.compatibility));
393
+ console.log("Appearance CSS path = ".concat(AppearanceStylePath));
394
+ console.log("AnimateCSS CSS path = ".concat(AnimateCSSPath));
395
+ }
396
+
397
+ loadStyle(AnimateCSSPath, 'stylesheet', function () {
398
+ loadStyle(AppearanceStylePath, 'stylesheet');
399
+ });
332
400
  appear(deck, options);
333
401
  };
334
402
 
@@ -340,4 +408,4 @@
340
408
 
341
409
  return Plugin;
342
410
 
343
- })));
411
+ }));