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,42 +4,67 @@ const Plugin = () => {
4
4
  // Scope support polyfill
5
5
  try{document.querySelector(":scope *")}catch(t){!function(t){let e=/:scope(?![\w-])/gi,r=u(t.querySelector);t.querySelector=function(t){return r.apply(this,arguments)};let c=u(t.querySelectorAll);if(t.querySelectorAll=function(t){return c.apply(this,arguments)},t.matches){let n=u(t.matches);t.matches=function(t){return n.apply(this,arguments)}}if(t.closest){let o=u(t.closest);t.closest=function(t){return o.apply(this,arguments)}}function u(t){return function(r){if(r&&e.test(r)){let c="q"+Math.floor(9e6*Math.random())+1e6;arguments[0]=r.replace(e,"["+c+"]"),this.setAttribute(c,"");let n=t.apply(this,arguments);return this.removeAttribute(c),n}return t.apply(this,arguments)}}}(Element.prototype)}
6
6
 
7
+ const loadStyle = function(url, type, callback) {
8
+ let head = document.querySelector('head');
9
+ let style;
10
+ style = document.createElement('link');
11
+ style.rel = 'stylesheet';
12
+ style.href = url;
13
+
14
+ let finish = function () {
15
+ if (typeof callback === 'function') {
16
+ callback.call();
17
+ callback = null;
18
+ }
19
+ };
20
+
21
+ style.onload = finish;
22
+
23
+ style.onreadystatechange = function () {
24
+ if (this.readyState === 'loaded') {
25
+ finish();
26
+ }
27
+ };
28
+ head.appendChild(style);
29
+ }
30
+
31
+ const selectionArray = function (container, selectors) {
32
+ let selections = container.querySelectorAll(selectors);
33
+ let selectionarray = Array.prototype.slice.call(selections);
34
+ return selectionarray;
35
+ };
36
+
7
37
  const appear = function (deck, options) {
8
38
 
39
+ let baseclass = 'animate__animated';
40
+ let appearanceSelector = options.compatibility ? `.${options.compatibilitybaseclass}` : `.${baseclass}`;
41
+ let fragmentSelector = ".fragment"
42
+
43
+ const sections = deck.getRevealElement().querySelectorAll(`.slides section`);
44
+ const fragments = deck.getRevealElement().querySelectorAll(fragmentSelector);
45
+ let animatecss = '[class^="animate__"],[class*=" animate__"]'
46
+
9
47
  const debugLog = function(text) {
10
48
  if (options.debug) console.log(text);
11
49
  }
12
50
 
13
- let timeouts = [];
14
-
15
- const clearTimeOuts = function (timeouts) {
16
- for (let i=0; i<timeouts.length; i++) {
17
- clearTimeout(timeouts[i]);
51
+ const findAppearancesIn = function (container, includeClass, excludeClass) {
52
+ if (!isStack(container)) {
53
+ let appearances = selectionArray(container, `:scope ${includeClass}`);
54
+ let excludes = selectionArray(container, `:scope ${excludeClass} ${includeClass}`);
55
+ let delay = 0;
56
+
57
+ appearances.filter(function (appearance, index) {
58
+ if ( !(excludes.indexOf(appearance) > -1 ) ) {
59
+ if ((index == 0 && appearance.dataset.delay) || index !=0) {
60
+ let elementDelay = appearance.dataset.delay ? (parseInt(appearance.dataset.delay)) : options.delay;
61
+ delay = delay + elementDelay;
62
+ appearance.style.setProperty('animation-delay', delay + "ms");
63
+ }
64
+ }
65
+ })
18
66
  }
19
- timeouts = [];
20
- };
21
-
22
- const loopAppearances = function (appearances, appearancesInFragment) {
23
- let delay = 0;
24
-
25
- appearances.filter(function (element, i) {
26
- if (!(appearancesInFragment.indexOf(element) > -1)) {
27
- let delayincrement = parseInt(element.dataset.delay ? element.dataset.delay : i > 0 ? options.delay : 0);
28
- delay += delayincrement;
29
- timeouts.push(
30
- setTimeout(function () {
31
- element.classList.add(options.visibleclass);
32
- }, delay)
33
- );
34
- }
35
- });
36
- };
37
-
38
- const selectionArray = function (container, selectors) {
39
- let selections = container.querySelectorAll(selectors);
40
- let selectionarray = Array.prototype.slice.call(selections);
41
- return selectionarray;
42
- };
67
+ }
43
68
 
44
69
  const autoAdd = function () {
45
70
 
@@ -55,33 +80,51 @@ const Plugin = () => {
55
80
 
56
81
  if (autoAppearances.length > 0) {
57
82
  autoAppearances.forEach(autoAppearance => {
58
- if (!autoAppearance.classList.contains(options.baseclass)) {
59
- autoAppearance.classList.add(options.baseclass);
83
+ if (!autoAppearance.classList.contains(baseclass)) {
84
+ autoAppearance.classList.add(baseclass);
60
85
  autoAppearance.classList.add(autoanimation);
61
86
  }
62
87
  });
63
88
  }
64
-
65
89
  }
66
90
  } else if (options.autoappear) {
67
91
  console.log(`Please set an "autoelements" object.`);
68
92
  }
69
93
  }
70
-
71
- const showAppearances = function (container) {
72
- clearTimeOuts(timeouts);
73
- let appearances = selectionArray(container, ":scope ." + options.baseclass);
74
- let appearancesInFragment = selectionArray(container, ":scope .fragment .".concat(options.baseclass));
75
94
 
76
- loopAppearances(appearances, appearancesInFragment);
95
+ const isStack = function (section) {
96
+ let isStack = false;
97
+ for (let i = 0; i < section.childNodes.length; i++) {
98
+ if (section.childNodes[i].tagName == "SECTION") {
99
+ isStack = true
100
+ break;
101
+ }
102
+ }
103
+ return isStack;
77
104
  };
105
+
106
+ if (options.compatibility) {
107
+ 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';
108
+ baseclass = options.compatibilitybaseclass
109
+ }
110
+
111
+ let allappearances = deck.getRevealElement().querySelectorAll(animatecss);
112
+
113
+ allappearances.forEach(appearance => {
114
+ if (!appearance.classList.contains(baseclass)) {
115
+ appearance.classList.add(baseclass);
116
+ }
117
+ });
118
+
119
+ autoAdd();
120
+
121
+ sections.forEach(section => {
122
+ findAppearancesIn(section, appearanceSelector, fragmentSelector);
123
+ })
78
124
 
79
- const hideAppearances = function (container) {
80
- let disappearances = selectionArray(container, ":scope .".concat(options.baseclass, ", :scope .fragment.visible"));
81
- disappearances.filter(function (element) {
82
- element.classList.remove(element.classList.contains("fragment") ? "visible" : options.visibleclass);
83
- });
84
- };
125
+ fragments.forEach(fragment => {
126
+ findAppearancesIn(fragment, appearanceSelector, fragmentSelector);
127
+ })
85
128
 
86
129
  const fromTo = function (event) {
87
130
  let slides = {}
@@ -90,39 +133,48 @@ const Plugin = () => {
90
133
  return slides
91
134
  }
92
135
 
93
- const showHideSlide = function (event) {
136
+ const showHideSlide = function(event) {
94
137
 
138
+ let etype = event.type;
95
139
  let slides = fromTo(event);
140
+ debugLog(etype);
96
141
 
97
- if (slides.to.dataset.appearevent == "auto") {slides.to.dataset.appearevent = "autoanimate"}
142
+ if (slides.to?.dataset.appearevent == "auto") {slides.to.dataset.appearevent = "autoanimate"}
98
143
  if (options.appearevent == "auto") {options.appearevent = "autoanimate"}
99
144
 
100
- if ( !slides.to.dataset.eventdone ) {
101
-
102
- debugLog(`Event: '${event.type}'`);
103
-
104
- if (event.type == "ready") {
105
- showAppearances(slides.to);
145
+ if (etype == "ready") {
146
+ slides.to.dataset.appearanceCanStart = true;
147
+ }
106
148
 
107
- } else if (event.type == slides.to.dataset.appearevent) {
108
- slides.to.dataset.eventdone = true;
109
- showAppearances(slides.to);
149
+ if (slides.to) {
110
150
 
111
- } else if (event.type == options.appearevent) {
112
-
113
- slides.to.dataset.eventdone = true;
114
- showAppearances(slides.to);
151
+ let appearevent = slides.to.dataset.appearevent ? slides.to.dataset.appearevent : options.appearevent;
115
152
 
116
- } else if (event.type == "slidetransitionend" && options.appearevent == "autoanimate" ) {
117
- slides.to.dataset.eventdone = true;
118
- showAppearances(slides.to);
153
+ if (etype == appearevent || (etype == "slidetransitionend" && appearevent == "autoanimate")) {
154
+ slides.to.dataset.appearanceCanStart = true;
155
+ }
119
156
 
120
- } else if (event.type == 'slidechanged' && document.body.dataset.exitoverview) {
121
- if (slides.from && options.hideagain) {
122
- hideAppearances(slides.to);
157
+ if (etype == "slidetransitionend") {
158
+ if (options.hideagain) {
159
+ if (slides.from) {
160
+ if (slides.from.dataset.appearanceCanStart) {
161
+ delete slides.from.dataset.appearanceCanStart;
162
+ }
163
+ let fromFragments = slides.from.querySelectorAll(`.fragment.visible`);
164
+ if (fromFragments) {
165
+ fromFragments.forEach(fragment => {
166
+ fragment.classList.remove('visible');
167
+ })
168
+ }
169
+ }
170
+ }
171
+ }
172
+
173
+ if (event.type == 'slidechanged' && document.body.dataset.exitoverview) {
174
+ if (options.hideagain) {
175
+ delete slides.from?.dataset.appearanceCanStart;
123
176
  }
124
- showAppearances(slides.to);
125
- slides.to.dataset.eventdone = true;
177
+ slides.to.dataset.appearanceCanStart = true;
126
178
 
127
179
  } else if (event.type == 'overviewhidden' ) {
128
180
 
@@ -133,54 +185,38 @@ const Plugin = () => {
133
185
  }, 500)
134
186
 
135
187
  if (event.currentSlide ) {
136
-
137
- if (slides.from && options.hideagain) {
138
- hideAppearances(event.previousSlide);
188
+ if (options.hideagain) {
189
+ delete slides.from?.dataset.appearanceCanStart;
139
190
  }
140
- showAppearances(slides.to);
141
- event.currentSlide.dataset.eventdone = true;
191
+ slides.to.dataset.appearanceCanStart = true;
142
192
  }
143
193
  }
144
194
  }
145
- if (event.type == "slidechanged" && slides.from) {
146
- slides.from.removeAttribute('data-eventdone');
147
- }
148
-
149
- if (slides.from ) {
150
- if (event.type == 'slidetransitionend' && options.hideagain) {
151
- hideAppearances(slides.from);
152
- }
153
- }
154
- };
155
-
156
- const showHideFragment = function (event) {
157
- if (event.type == "fragmentshowncomplete" || event.type == "fragmentshown") {
158
- showAppearances(event.fragment);
159
- } else {
160
- hideAppearances(event.fragment);
161
- }
162
- };
195
+ }
163
196
 
164
- deck.on( 'ready', event => { autoAdd(); showHideSlide(event) } );
165
- deck.on( 'slidechanged', event => { showHideSlide(event) } );
166
- deck.on( 'slidetransitionend', event => { showHideSlide(event) } );
167
- deck.on( 'autoanimate', event => { showHideSlide(event) } );
168
- deck.on( 'overviewhidden', event => { showHideSlide(event) } );
169
- deck.on( 'fragmentshown', event => { showHideFragment(event) });
170
- deck.on( 'fragmenthidden', event => { showHideFragment(event) });
197
+ const eventnames = ['ready', 'slidechanged', 'slidetransitionend', 'autoanimate', 'overviewhidden'];
198
+ eventnames.forEach( (eventname) => deck.on( eventname, event => { showHideSlide(event) } ) )
171
199
  };
172
200
 
173
201
  const init = function (deck) {
174
202
 
203
+ let es5Filename = "appearance.js"
204
+
175
205
  let defaultOptions = {
176
- baseclass: 'animated',
177
- visibleclass: 'in',
206
+ baseclass: 'animate__animated',
178
207
  hideagain: true,
179
208
  delay: 300,
180
209
  debug: false,
181
210
  appearevent: 'slidetransitionend',
182
211
  autoappear: false,
183
- autoelements: null
212
+ autoelements: false,
213
+ csspath: '',
214
+ animatecsspath: {
215
+ link : 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css',
216
+ compat : 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.0.0/animate.compat.css',
217
+ },
218
+ compatibility: false,
219
+ compatibilitybaseclass: 'animated'
184
220
  };
185
221
 
186
222
  const defaults = function (options, defaultOptions) {
@@ -194,8 +230,32 @@ const Plugin = () => {
194
230
  let options = deck.getConfig().appearance || {};
195
231
  defaults(options, defaultOptions);
196
232
 
197
- appear(deck, options);
233
+ function pluginPath() {
234
+ let path;
235
+ let pluginScript = document.querySelector(`script[src$="${es5Filename}"]`);
236
+ if (pluginScript) {
237
+ path = pluginScript.getAttribute("src").slice(0, -1 * (es5Filename.length));
238
+ } else {
239
+ path = import.meta.url.slice(0, import.meta.url.lastIndexOf('/') + 1);
240
+ }
241
+ return path;
242
+ }
198
243
 
244
+ let AppearanceStylePath = options.csspath.appearance ? options.csspath.appearance : null || `${pluginPath()}appearance.css` || 'plugin/appearance/appearance.css'
245
+ let AnimateCSSPath = !options.compatibility ? options.animatecsspath.link : options.animatecsspath.compat;
246
+
247
+ if (options.debug) {
248
+ console.log(`Plugin path = ${pluginPath()}`);
249
+ console.log(`Compatibility mode: ${options.compatibility}`)
250
+ console.log(`Appearance CSS path = ${AppearanceStylePath}`);
251
+ console.log(`AnimateCSS CSS path = ${AnimateCSSPath}`);
252
+ }
253
+
254
+ loadStyle(AnimateCSSPath, 'stylesheet', function () {
255
+ loadStyle(AppearanceStylePath, 'stylesheet');
256
+ });
257
+
258
+ appear(deck, options);
199
259
  };
200
260
 
201
261
  return {
package/screenshot.png CHANGED
Binary file