reveal.js-appearance 1.0.9 → 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,56 +4,127 @@ 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 = [];
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
+ })
66
+ }
67
+ }
68
+
69
+ const autoAdd = function () {
70
+
71
+ if (options.autoelements) {
14
72
 
15
- const clearTimeOuts = function (timeouts) {
16
- for (let i=0; i<timeouts.length; i++) {
17
- clearTimeout(timeouts[i]);
73
+ for (const [autoelement, autoanimation] of Object.entries(options.autoelements)) {
74
+
75
+ if (options.autoappear) {
76
+ debugLog(`All "${autoelement}"" elements will animate with ${autoanimation}`);
77
+ }
78
+ let autosection = options.autoappear ? "" : "[data-autoappear] ";
79
+ let autoAppearances = deck.getRevealElement().querySelectorAll(`.slides ${autosection}${autoelement}`);
80
+
81
+ if (autoAppearances.length > 0) {
82
+ autoAppearances.forEach(autoAppearance => {
83
+ if (!autoAppearance.classList.contains(baseclass)) {
84
+ autoAppearance.classList.add(baseclass);
85
+ autoAppearance.classList.add(autoanimation);
86
+ }
87
+ });
88
+ }
89
+ }
90
+ } else if (options.autoappear) {
91
+ console.log(`Please set an "autoelements" object.`);
18
92
  }
19
- timeouts = [];
20
- };
93
+ }
21
94
 
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
- );
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;
34
101
  }
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
- };
43
-
44
- const showAppearances = function (container) {
45
- clearTimeOuts(timeouts);
46
- let appearances = selectionArray(container, ":scope ." + options.baseclass);
47
- let appearancesInFragment = selectionArray(container, ":scope .fragment .".concat(options.baseclass));
48
- loopAppearances(appearances, appearancesInFragment);
102
+ }
103
+ return isStack;
49
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
+ })
50
124
 
51
- const hideAppearances = function (container) {
52
- let disappearances = selectionArray(container, ":scope .".concat(options.baseclass, ", :scope .fragment.visible"));
53
- disappearances.filter(function (element) {
54
- element.classList.remove(element.classList.contains("fragment") ? "visible" : options.visibleclass);
55
- });
56
- };
125
+ fragments.forEach(fragment => {
126
+ findAppearancesIn(fragment, appearanceSelector, fragmentSelector);
127
+ })
57
128
 
58
129
  const fromTo = function (event) {
59
130
  let slides = {}
@@ -62,39 +133,42 @@ const Plugin = () => {
62
133
  return slides
63
134
  }
64
135
 
65
- const showHideSlide = function (event) {
136
+ const showHideSlide = function(event) {
66
137
 
138
+ let etype = event.type;
67
139
  let slides = fromTo(event);
140
+ debugLog(etype);
68
141
 
69
- if (slides.to.dataset.appearevent == "auto") {slides.to.dataset.appearevent = "autoanimate"}
142
+ if (slides.to?.dataset.appearevent == "auto") {slides.to.dataset.appearevent = "autoanimate"}
70
143
  if (options.appearevent == "auto") {options.appearevent = "autoanimate"}
71
144
 
72
- if ( !slides.to.dataset.eventdone ) {
73
-
74
- debugLog(`Event: '${event.type}'`);
75
-
76
- if (event.type == "ready") {
77
- showAppearances(slides.to);
145
+ if (etype == "ready") {
146
+ slides.to.dataset.appearanceCanStart = true;
147
+ }
78
148
 
79
- } else if (event.type == slides.to.dataset.appearevent) {
80
- slides.to.dataset.eventdone = true;
81
- showAppearances(slides.to);
149
+ if (slides.to) {
82
150
 
83
- } else if (event.type == options.appearevent) {
84
-
85
- slides.to.dataset.eventdone = true;
86
- showAppearances(slides.to);
151
+ let appearevent = slides.to.dataset.appearevent ? slides.to.dataset.appearevent : options.appearevent;
87
152
 
88
- } else if (event.type == "slidetransitionend" && options.appearevent == "autoanimate" ) {
89
- slides.to.dataset.eventdone = true;
90
- showAppearances(slides.to);
153
+ if (etype == appearevent || (etype == "slidetransitionend" && appearevent == "autoanimate")) {
154
+ slides.to.dataset.appearanceCanStart = true;
155
+ }
91
156
 
92
- } else if (event.type == 'slidechanged' && document.body.dataset.exitoverview) {
93
- if (slides.from && options.hideagain) {
94
- 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
+ })
164
+ }
165
+ }
166
+
167
+ if (event.type == 'slidechanged' && document.body.dataset.exitoverview) {
168
+ if (options.hideagain) {
169
+ delete slides.from?.dataset.appearanceCanStart;
95
170
  }
96
- showAppearances(slides.to);
97
- slides.to.dataset.eventdone = true;
171
+ slides.to.dataset.appearanceCanStart = true;
98
172
 
99
173
  } else if (event.type == 'overviewhidden' ) {
100
174
 
@@ -105,53 +179,38 @@ const Plugin = () => {
105
179
  }, 500)
106
180
 
107
181
  if (event.currentSlide ) {
108
-
109
- if (slides.from && options.hideagain) {
110
- hideAppearances(event.previousSlide);
182
+ if (options.hideagain) {
183
+ delete slides.from?.dataset.appearanceCanStart;
111
184
  }
112
- showAppearances(slides.to);
113
- event.currentSlide.dataset.eventdone = true;
185
+ slides.to.dataset.appearanceCanStart = true;
114
186
  }
115
187
  }
116
188
  }
117
- if (event.type == "slidechanged" && slides.from) {
118
- slides.from.removeAttribute('data-eventdone');
119
- }
120
-
121
- if (slides.from ) {
122
- if (event.type == 'slidetransitionend' && options.hideagain) {
123
- hideAppearances(slides.from);
124
- }
125
- }
126
- };
127
-
128
-
129
- const showHideFragment = function (event) {
130
- if (event.type == "fragmentshowncomplete" || event.type == "fragmentshown") {
131
- showAppearances(event.fragment);
132
- } else {
133
- hideAppearances(event.fragment);
134
- }
135
- };
189
+ }
136
190
 
137
- deck.on( 'ready', event => { showHideSlide(event) } );
138
- deck.on( 'slidechanged', event => { showHideSlide(event) } );
139
- deck.on( 'slidetransitionend', event => { showHideSlide(event) } );
140
- deck.on( 'autoanimate', event => { showHideSlide(event) } );
141
- deck.on( 'overviewhidden', event => { showHideSlide(event) } );
142
- deck.on( 'fragmentshown', event => { showHideFragment(event) });
143
- deck.on( 'fragmenthidden', event => { showHideFragment(event) });
191
+ const eventnames = ['ready', 'slidechanged', 'slidetransitionend', 'autoanimate', 'overviewhidden'];
192
+ eventnames.forEach( (eventname) => deck.on( eventname, event => { showHideSlide(event) } ) )
144
193
  };
145
194
 
146
195
  const init = function (deck) {
147
196
 
197
+ let es5Filename = "appearance.js"
198
+
148
199
  let defaultOptions = {
149
- baseclass: 'animated',
150
- visibleclass: 'in',
200
+ baseclass: 'animate__animated',
151
201
  hideagain: true,
152
202
  delay: 300,
153
203
  debug: false,
154
204
  appearevent: 'slidetransitionend',
205
+ autoappear: false,
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'
155
214
  };
156
215
 
157
216
  const defaults = function (options, defaultOptions) {
@@ -165,8 +224,32 @@ const Plugin = () => {
165
224
  let options = deck.getConfig().appearance || {};
166
225
  defaults(options, defaultOptions);
167
226
 
168
- 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
+ }
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;
169
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);
170
253
  };
171
254
 
172
255
  return {
package/screenshot.png CHANGED
Binary file