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
@@ -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,37 @@ 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
+ 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
+ });
240
294
  }
295
+ }
241
296
 
242
- showAppearances(slides.to);
243
- slides.to.dataset.eventdone = true;
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;
302
+ }
303
+
304
+ slides.to.dataset.appearanceCanStart = true;
244
305
  } else if (event.type == 'overviewhidden') {
245
306
  document.body.dataset.exitoverview = true;
246
307
  setTimeout(function () {
@@ -248,69 +309,43 @@ var Plugin = function Plugin() {
248
309
  }, 500);
249
310
 
250
311
  if (event.currentSlide) {
251
- if (slides.from && options.hideagain) {
252
- 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;
253
316
  }
254
317
 
255
- showAppearances(slides.to);
256
- event.currentSlide.dataset.eventdone = true;
318
+ slides.to.dataset.appearanceCanStart = true;
257
319
  }
258
320
  }
259
321
  }
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
322
  };
279
323
 
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);
324
+ var eventnames = ['ready', 'slidechanged', 'slidetransitionend', 'autoanimate', 'overviewhidden'];
325
+ eventnames.forEach(function (eventname) {
326
+ return deck.on(eventname, function (event) {
327
+ showHideSlide(event);
328
+ });
301
329
  });
302
330
  };
303
331
 
304
332
  var init = function init(deck) {
333
+ var es5Filename = "appearance.js";
305
334
  var defaultOptions = {
306
- baseclass: 'animated',
307
- visibleclass: 'in',
335
+ baseclass: 'animate__animated',
308
336
  hideagain: true,
309
337
  delay: 300,
310
338
  debug: false,
311
339
  appearevent: 'slidetransitionend',
312
340
  autoappear: false,
313
- autoelements: null
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'
314
349
  };
315
350
 
316
351
  var defaults = function defaults(options, defaultOptions) {
@@ -323,6 +358,33 @@ var Plugin = function Plugin() {
323
358
 
324
359
  var options = deck.getConfig().appearance || {};
325
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
+ });
326
388
  appear(deck, options);
327
389
  };
328
390
 
@@ -332,4 +394,4 @@ var Plugin = function Plugin() {
332
394
  };
333
395
  };
334
396
 
335
- export default Plugin;
397
+ export { Plugin as default };