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
@@ -24,14 +24,17 @@ function _arrayWithHoles(arr) {
24
24
  }
25
25
 
26
26
  function _iterableToArrayLimit(arr, i) {
27
- if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
27
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
28
+
29
+ if (_i == null) return;
28
30
  var _arr = [];
29
31
  var _n = true;
30
32
  var _d = false;
31
- var _e = undefined;
33
+
34
+ var _s, _e;
32
35
 
33
36
  try {
34
- for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
37
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
35
38
  _arr.push(_s.value);
36
39
 
37
40
  if (i && _arr.length === i) break;
@@ -122,38 +125,64 @@ var Plugin = function Plugin() {
122
125
  }(Element.prototype);
123
126
  }
124
127
 
125
- var appear = function appear(deck, options) {
126
- var debugLog = function debugLog(text) {
127
- if (options.debug) console.log(text);
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
+ }
128
140
  };
129
141
 
130
- var timeouts = [];
142
+ style.onload = finish;
131
143
 
132
- var clearTimeOuts = function clearTimeOuts(timeouts) {
133
- for (var i = 0; i < timeouts.length; i++) {
134
- clearTimeout(timeouts[i]);
144
+ style.onreadystatechange = function () {
145
+ if (this.readyState === 'loaded') {
146
+ finish();
135
147
  }
136
-
137
- timeouts = [];
138
148
  };
139
149
 
140
- var loopAppearances = function loopAppearances(appearances, appearancesInFragment) {
141
- var delay = 0;
142
- appearances.filter(function (element, i) {
143
- if (!(appearancesInFragment.indexOf(element) > -1)) {
144
- var delayincrement = parseInt(element.dataset.delay ? element.dataset.delay : i > 0 ? options.delay : 0);
145
- delay += delayincrement;
146
- timeouts.push(setTimeout(function () {
147
- element.classList.add(options.visibleclass);
148
- }, delay));
149
- }
150
- });
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
+
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
+
167
+ var debugLog = function debugLog(text) {
168
+ if (options.debug) console.log(text);
151
169
  };
152
170
 
153
- var selectionArray = function selectionArray(container, selectors) {
154
- var selections = container.querySelectorAll(selectors);
155
- var selectionarray = Array.prototype.slice.call(selections);
156
- return selectionarray;
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
+ });
185
+ }
157
186
  };
158
187
 
159
188
  var autoAdd = function autoAdd() {
@@ -172,8 +201,8 @@ var Plugin = function Plugin() {
172
201
 
173
202
  if (autoAppearances.length > 0) {
174
203
  autoAppearances.forEach(function (autoAppearance) {
175
- if (!autoAppearance.classList.contains(options.baseclass)) {
176
- autoAppearance.classList.add(options.baseclass);
204
+ if (!autoAppearance.classList.contains(baseclass)) {
205
+ autoAppearance.classList.add(baseclass);
177
206
  autoAppearance.classList.add(autoanimation);
178
207
  }
179
208
  });
@@ -188,20 +217,38 @@ var Plugin = function Plugin() {
188
217
  }
189
218
  };
190
219
 
191
- var showAppearances = function showAppearances(container) {
192
- clearTimeOuts(timeouts);
193
- var appearances = selectionArray(container, ":scope ." + options.baseclass);
194
- var appearancesInFragment = selectionArray(container, ":scope .fragment .".concat(options.baseclass));
195
- loopAppearances(appearances, appearancesInFragment);
196
- };
220
+ var isStack = function isStack(section) {
221
+ var isStack = false;
197
222
 
198
- var hideAppearances = function hideAppearances(container) {
199
- var disappearances = selectionArray(container, ":scope .".concat(options.baseclass, ", :scope .fragment.visible"));
200
- disappearances.filter(function (element) {
201
- element.classList.remove(element.classList.contains("fragment") ? "visible" : options.visibleclass);
202
- });
223
+ for (var i = 0; i < section.childNodes.length; i++) {
224
+ if (section.childNodes[i].tagName == "SECTION") {
225
+ isStack = true;
226
+ break;
227
+ }
228
+ }
229
+
230
+ return isStack;
203
231
  };
204
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
+
205
252
  var fromTo = function fromTo(event) {
206
253
  var slides = {};
207
254
  slides.from = event.fromSlide ? event.fromSlide : event.previousSlide ? event.previousSlide : null;
@@ -210,9 +257,13 @@ var Plugin = function Plugin() {
210
257
  };
211
258
 
212
259
  var showHideSlide = function showHideSlide(event) {
260
+ var _slides$to;
261
+
262
+ var etype = event.type;
213
263
  var slides = fromTo(event);
264
+ debugLog(etype);
214
265
 
215
- if (slides.to.dataset.appearevent == "auto") {
266
+ if (((_slides$to = slides.to) === null || _slides$to === void 0 ? void 0 : _slides$to.dataset.appearevent) == "auto") {
216
267
  slides.to.dataset.appearevent = "autoanimate";
217
268
  }
218
269
 
@@ -220,27 +271,43 @@ var Plugin = function Plugin() {
220
271
  options.appearevent = "autoanimate";
221
272
  }
222
273
 
223
- if (!slides.to.dataset.eventdone) {
224
- debugLog("Event: '".concat(event.type, "'"));
225
-
226
- if (event.type == "ready") {
227
- showAppearances(slides.to);
228
- } else if (event.type == slides.to.dataset.appearevent) {
229
- slides.to.dataset.eventdone = true;
230
- showAppearances(slides.to);
231
- } else if (event.type == options.appearevent) {
232
- slides.to.dataset.eventdone = true;
233
- showAppearances(slides.to);
234
- } else if (event.type == "slidetransitionend" && options.appearevent == "autoanimate") {
235
- slides.to.dataset.eventdone = true;
236
- showAppearances(slides.to);
237
- } else if (event.type == 'slidechanged' && document.body.dataset.exitoverview) {
238
- if (slides.from && options.hideagain) {
239
- 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
+ if (slides.from) {
288
+ if (slides.from.dataset.appearanceCanStart) {
289
+ delete slides.from.dataset.appearanceCanStart;
290
+ }
291
+
292
+ var fromFragments = slides.from.querySelectorAll(".fragment.visible");
293
+
294
+ if (fromFragments) {
295
+ fromFragments.forEach(function (fragment) {
296
+ fragment.classList.remove('visible');
297
+ });
298
+ }
299
+ }
240
300
  }
301
+ }
302
+
303
+ if (event.type == 'slidechanged' && document.body.dataset.exitoverview) {
304
+ if (options.hideagain) {
305
+ var _slides$from;
241
306
 
242
- showAppearances(slides.to);
243
- slides.to.dataset.eventdone = true;
307
+ (_slides$from = slides.from) === null || _slides$from === void 0 ? true : delete _slides$from.dataset.appearanceCanStart;
308
+ }
309
+
310
+ slides.to.dataset.appearanceCanStart = true;
244
311
  } else if (event.type == 'overviewhidden') {
245
312
  document.body.dataset.exitoverview = true;
246
313
  setTimeout(function () {
@@ -248,69 +315,43 @@ var Plugin = function Plugin() {
248
315
  }, 500);
249
316
 
250
317
  if (event.currentSlide) {
251
- if (slides.from && options.hideagain) {
252
- hideAppearances(event.previousSlide);
318
+ if (options.hideagain) {
319
+ var _slides$from2;
320
+
321
+ (_slides$from2 = slides.from) === null || _slides$from2 === void 0 ? true : delete _slides$from2.dataset.appearanceCanStart;
253
322
  }
254
323
 
255
- showAppearances(slides.to);
256
- event.currentSlide.dataset.eventdone = true;
324
+ slides.to.dataset.appearanceCanStart = true;
257
325
  }
258
326
  }
259
327
  }
260
-
261
- if (event.type == "slidechanged" && slides.from) {
262
- slides.from.removeAttribute('data-eventdone');
263
- }
264
-
265
- if (slides.from) {
266
- if (event.type == 'slidetransitionend' && options.hideagain) {
267
- hideAppearances(slides.from);
268
- }
269
- }
270
- };
271
-
272
- var showHideFragment = function showHideFragment(event) {
273
- if (event.type == "fragmentshowncomplete" || event.type == "fragmentshown") {
274
- showAppearances(event.fragment);
275
- } else {
276
- hideAppearances(event.fragment);
277
- }
278
328
  };
279
329
 
280
- deck.on('ready', function (event) {
281
- autoAdd();
282
- showHideSlide(event);
283
- });
284
- deck.on('slidechanged', function (event) {
285
- showHideSlide(event);
286
- });
287
- deck.on('slidetransitionend', function (event) {
288
- showHideSlide(event);
289
- });
290
- deck.on('autoanimate', function (event) {
291
- showHideSlide(event);
292
- });
293
- deck.on('overviewhidden', function (event) {
294
- showHideSlide(event);
295
- });
296
- deck.on('fragmentshown', function (event) {
297
- showHideFragment(event);
298
- });
299
- deck.on('fragmenthidden', function (event) {
300
- 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
+ });
301
335
  });
302
336
  };
303
337
 
304
338
  var init = function init(deck) {
339
+ var es5Filename = "appearance.js";
305
340
  var defaultOptions = {
306
- baseclass: 'animated',
307
- visibleclass: 'in',
341
+ baseclass: 'animate__animated',
308
342
  hideagain: true,
309
343
  delay: 300,
310
344
  debug: false,
311
345
  appearevent: 'slidetransitionend',
312
346
  autoappear: false,
313
- 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'
314
355
  };
315
356
 
316
357
  var defaults = function defaults(options, defaultOptions) {
@@ -323,6 +364,33 @@ var Plugin = function Plugin() {
323
364
 
324
365
  var options = deck.getConfig().appearance || {};
325
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 = import.meta.url.slice(0, import.meta.url.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
+ });
326
394
  appear(deck, options);
327
395
  };
328
396
 
@@ -332,4 +400,4 @@ var Plugin = function Plugin() {
332
400
  };
333
401
  };
334
402
 
335
- export default Plugin;
403
+ export { Plugin as default };