reveal.js-appearance 1.1.1 → 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.1.1
7
+ * Version 1.1.2
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,37 @@
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
+ var _slides$from;
294
+
295
+ (_slides$from = slides.from) === null || _slides$from === void 0 ? true : delete _slides$from.dataset.appearanceCanStart;
296
+ var fromFragments = slides.from.querySelectorAll(".fragment.visible");
297
+ fromFragments.forEach(function (fragment) {
298
+ fragment.classList.remove('visible');
299
+ });
246
300
  }
301
+ }
247
302
 
248
- showAppearances(slides.to);
249
- slides.to.dataset.eventdone = true;
303
+ if (event.type == 'slidechanged' && document.body.dataset.exitoverview) {
304
+ if (options.hideagain) {
305
+ var _slides$from2;
306
+
307
+ (_slides$from2 = slides.from) === null || _slides$from2 === void 0 ? true : delete _slides$from2.dataset.appearanceCanStart;
308
+ }
309
+
310
+ slides.to.dataset.appearanceCanStart = true;
250
311
  } else if (event.type == 'overviewhidden') {
251
312
  document.body.dataset.exitoverview = true;
252
313
  setTimeout(function () {
@@ -254,69 +315,43 @@
254
315
  }, 500);
255
316
 
256
317
  if (event.currentSlide) {
257
- if (slides.from && options.hideagain) {
258
- hideAppearances(event.previousSlide);
318
+ if (options.hideagain) {
319
+ var _slides$from3;
320
+
321
+ (_slides$from3 = slides.from) === null || _slides$from3 === void 0 ? true : delete _slides$from3.dataset.appearanceCanStart;
259
322
  }
260
323
 
261
- showAppearances(slides.to);
262
- event.currentSlide.dataset.eventdone = true;
324
+ slides.to.dataset.appearanceCanStart = true;
263
325
  }
264
326
  }
265
327
  }
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
328
  };
285
329
 
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);
330
+ var eventnames = ['ready', 'slidechanged', 'slidetransitionend', 'autoanimate', 'overviewhidden'];
331
+ eventnames.forEach(function (eventname) {
332
+ return deck.on(eventname, function (event) {
333
+ showHideSlide(event);
334
+ });
307
335
  });
308
336
  };
309
337
 
310
338
  var init = function init(deck) {
339
+ var es5Filename = "appearance.js";
311
340
  var defaultOptions = {
312
- baseclass: 'animated',
313
- visibleclass: 'in',
341
+ baseclass: 'animate__animated',
314
342
  hideagain: true,
315
343
  delay: 300,
316
344
  debug: false,
317
345
  appearevent: 'slidetransitionend',
318
346
  autoappear: false,
319
- autoelements: null
347
+ autoelements: false,
348
+ csspath: '',
349
+ animatecsspath: {
350
+ link: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css',
351
+ compat: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.0.0/animate.compat.css'
352
+ },
353
+ compatibility: false,
354
+ compatibilitybaseclass: 'animated'
320
355
  };
321
356
 
322
357
  var defaults = function defaults(options, defaultOptions) {
@@ -329,6 +364,33 @@
329
364
 
330
365
  var options = deck.getConfig().appearance || {};
331
366
  defaults(options, defaultOptions);
367
+
368
+ function pluginPath() {
369
+ var path;
370
+ var pluginScript = document.querySelector("script[src$=\"".concat(es5Filename, "\"]"));
371
+
372
+ if (pluginScript) {
373
+ path = pluginScript.getAttribute("src").slice(0, -1 * es5Filename.length);
374
+ } else {
375
+ 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);
376
+ }
377
+
378
+ return path;
379
+ }
380
+
381
+ var AppearanceStylePath = options.csspath.appearance ? options.csspath.appearance : "".concat(pluginPath(), "appearance.css") || 'plugin/appearance/appearance.css';
382
+ var AnimateCSSPath = !options.compatibility ? options.animatecsspath.link : options.animatecsspath.compat;
383
+
384
+ if (options.debug) {
385
+ console.log("Plugin path = ".concat(pluginPath()));
386
+ console.log("Compatibility mode: ".concat(options.compatibility));
387
+ console.log("Appearance CSS path = ".concat(AppearanceStylePath));
388
+ console.log("AnimateCSS CSS path = ".concat(AnimateCSSPath));
389
+ }
390
+
391
+ loadStyle(AnimateCSSPath, 'stylesheet', function () {
392
+ loadStyle(AppearanceStylePath, 'stylesheet');
393
+ });
332
394
  appear(deck, options);
333
395
  };
334
396
 
@@ -340,4 +402,4 @@
340
402
 
341
403
  return Plugin;
342
404
 
343
- })));
405
+ }));