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,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,42 @@ 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
+ delete slides.from?.dataset.appearanceCanStart;
160
+ let fromFragments = slides.from.querySelectorAll(`.fragment.visible`);
161
+ fromFragments.forEach(fragment => {
162
+ fragment.classList.remove('visible');
163
+ })
123
164
  }
124
- showAppearances(slides.to);
125
- slides.to.dataset.eventdone = true;
165
+ }
166
+
167
+ if (event.type == 'slidechanged' && document.body.dataset.exitoverview) {
168
+ if (options.hideagain) {
169
+ delete slides.from?.dataset.appearanceCanStart;
170
+ }
171
+ slides.to.dataset.appearanceCanStart = true;
126
172
 
127
173
  } else if (event.type == 'overviewhidden' ) {
128
174
 
@@ -133,54 +179,38 @@ const Plugin = () => {
133
179
  }, 500)
134
180
 
135
181
  if (event.currentSlide ) {
136
-
137
- if (slides.from && options.hideagain) {
138
- hideAppearances(event.previousSlide);
182
+ if (options.hideagain) {
183
+ delete slides.from?.dataset.appearanceCanStart;
139
184
  }
140
- showAppearances(slides.to);
141
- event.currentSlide.dataset.eventdone = true;
185
+ slides.to.dataset.appearanceCanStart = true;
142
186
  }
143
187
  }
144
188
  }
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
- };
189
+ }
163
190
 
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) });
191
+ const eventnames = ['ready', 'slidechanged', 'slidetransitionend', 'autoanimate', 'overviewhidden'];
192
+ eventnames.forEach( (eventname) => deck.on( eventname, event => { showHideSlide(event) } ) )
171
193
  };
172
194
 
173
195
  const init = function (deck) {
174
196
 
197
+ let es5Filename = "appearance.js"
198
+
175
199
  let defaultOptions = {
176
- baseclass: 'animated',
177
- visibleclass: 'in',
200
+ baseclass: 'animate__animated',
178
201
  hideagain: true,
179
202
  delay: 300,
180
203
  debug: false,
181
204
  appearevent: 'slidetransitionend',
182
205
  autoappear: false,
183
- autoelements: null
206
+ autoelements: false,
207
+ csspath: '',
208
+ animatecsspath: {
209
+ link : 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css',
210
+ compat : 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.0.0/animate.compat.css',
211
+ },
212
+ compatibility: false,
213
+ compatibilitybaseclass: 'animated'
184
214
  };
185
215
 
186
216
  const defaults = function (options, defaultOptions) {
@@ -194,8 +224,32 @@ const Plugin = () => {
194
224
  let options = deck.getConfig().appearance || {};
195
225
  defaults(options, defaultOptions);
196
226
 
197
- appear(deck, options);
227
+ function pluginPath() {
228
+ let path;
229
+ let pluginScript = document.querySelector(`script[src$="${es5Filename}"]`);
230
+ if (pluginScript) {
231
+ path = pluginScript.getAttribute("src").slice(0, -1 * (es5Filename.length));
232
+ } else {
233
+ path = import.meta.url.slice(0, import.meta.url.lastIndexOf('/') + 1);
234
+ }
235
+ return path;
236
+ }
198
237
 
238
+ let AppearanceStylePath = options.csspath.appearance ? options.csspath.appearance : null || `${pluginPath()}appearance.css` || 'plugin/appearance/appearance.css'
239
+ let AnimateCSSPath = !options.compatibility ? options.animatecsspath.link : options.animatecsspath.compat;
240
+
241
+ if (options.debug) {
242
+ console.log(`Plugin path = ${pluginPath()}`);
243
+ console.log(`Compatibility mode: ${options.compatibility}`)
244
+ console.log(`Appearance CSS path = ${AppearanceStylePath}`);
245
+ console.log(`AnimateCSS CSS path = ${AnimateCSSPath}`);
246
+ }
247
+
248
+ loadStyle(AnimateCSSPath, 'stylesheet', function () {
249
+ loadStyle(AppearanceStylePath, 'stylesheet');
250
+ });
251
+
252
+ appear(deck, options);
199
253
  };
200
254
 
201
255
  return {
package/screenshot.png CHANGED
Binary file