move out additional util methods, use shorthands for api
This commit is contained in:
1 parent
313ad46e30
commit
4cfd254086
4 files changed
+264
-271
No files matched your search
@@ -406,9 +406,14 @@ Reveal.addEventListener( 'customevent', function() {
|
||||
|
||||
</div>
|
||||
|
||||
<script src="dist/reveal.min.js"></script>
|
||||
<script type="module" src="js/index.js"></script>
|
||||
|
||||
<script>
|
||||
<script type="module">
|
||||
|
||||
// WIP support for multiple reveal.js instances
|
||||
// let a = new Reveal(document.querySelector( '.reveal' ), {controls: false});
|
||||
// let b = new Reveal(document.querySelector( '.reveal' ), {controls: true});
|
||||
// console.log(a.getConfig().controls,b.getConfig().controls);
|
||||
|
||||
// More info https://github.com/hakimel/reveal.js#configuration
|
||||
Reveal.initialize({
|
||||
|
||||
Vendored
+1
-1
@@ -5,4 +5,4 @@
|
||||
*
|
||||
* Copyright (C) 2020 Hakim El Hattab, https://hakim.se
|
||||
*/
|
||||
!function(e){var t={};function a(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,a),r.l=!0,r.exports}a.m=e,a.c=t,a.d=function(e,t,n){a.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,t){if(1&t&&(e=a(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(a.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)a.d(n,r,function(t){return e[t]}.bind(null,r));return n},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="",a(a.s=0)}([function(e,t,a){"use strict";a.r(t);class n{constructor(e,t){this.diameter=100,this.diameter2=this.diameter/2,this.thickness=6,this.playing=!1,this.progress=0,this.progressOffset=1,this.container=e,this.progressCheck=t,this.canvas=document.createElement("canvas"),this.canvas.className="playback",this.canvas.width=this.diameter,this.canvas.height=this.diameter,this.canvas.style.width=this.diameter2+"px",this.canvas.style.height=this.diameter2+"px",this.context=this.canvas.getContext("2d"),this.container.appendChild(this.canvas),this.render()}setPlaying(e){const t=this.playing;this.playing=e,!t&&this.playing?this.animate():this.render()}animate(){const e=this.progress;this.progress=this.progressCheck(),e>.8&&this.progress<.2&&(this.progressOffset=this.progress),this.render(),this.playing&&requestAnimationFrame(this.animate.bind(this))}render(){let e=this.playing?this.progress:0,t=this.diameter2-this.thickness,a=this.diameter2,n=this.diameter2;this.progressOffset+=.1*(1-this.progressOffset);const r=-Math.PI/2+e*(2*Math.PI),i=-Math.PI/2+this.progressOffset*(2*Math.PI);this.context.save(),this.context.clearRect(0,0,this.diameter,this.diameter),this.context.beginPath(),this.context.arc(a,n,t+4,0,2*Math.PI,!1),this.context.fillStyle="rgba( 0, 0, 0, 0.4 )",this.context.fill(),this.context.beginPath(),this.context.arc(a,n,t,0,2*Math.PI,!1),this.context.lineWidth=this.thickness,this.context.strokeStyle="rgba( 255, 255, 255, 0.2 )",this.context.stroke(),this.playing&&(this.context.beginPath(),this.context.arc(a,n,t,i,r,!1),this.context.lineWidth=this.thickness,this.context.strokeStyle="#fff",this.context.stroke()),this.context.translate(a-14,n-14),this.playing?(this.context.fillStyle="#fff",this.context.fillRect(0,0,10,28),this.context.fillRect(18,0,10,28)):(this.context.beginPath(),this.context.translate(4,0),this.context.moveTo(0,0),this.context.lineTo(24,14),this.context.lineTo(0,28),this.context.fillStyle="#fff",this.context.fill()),this.context.restore()}on(e,t){this.canvas.addEventListener(e,t,!1)}off(e,t){this.canvas.removeEventListener(e,t,!1)}destroy(){this.playing=!1,this.canvas.parentNode&&this.container.removeChild(this.canvas)}}var r={width:960,height:700,margin:.04,minScale:.2,maxScale:2,controls:!0,controlsTutorial:!0,controlsLayout:"bottom-right",controlsBackArrows:"faded",progress:!0,slideNumber:!1,showSlideNumber:"all",hashOneBasedIndex:!1,hash:!1,history:!1,keyboard:!0,keyboardCondition:null,overview:!0,disableLayout:!1,center:!0,touch:!0,loop:!1,rtl:!1,navigationMode:"default",shuffle:!1,fragments:!0,fragmentInURL:!1,embedded:!1,help:!0,pause:!0,showNotes:!1,autoPlayMedia:null,preloadIframes:null,autoAnimate:!0,autoAnimateMatcher:null,autoAnimateEasing:"ease",autoAnimateDuration:1,autoAnimateUnmatched:!0,autoAnimateStyles:["opacity","color","background-color","padding","font-size","line-height","letter-spacing","border-width","border-color","border-radius","outline","outline-offset"],autoSlide:0,autoSlideStoppable:!0,autoSlideMethod:null,defaultTiming:null,mouseWheel:!1,previewLinks:!1,postMessage:!0,postMessageEvents:!1,focusBodyOnPageVisibilityChange:!0,transition:"slide",transitionSpeed:"default",backgroundTransition:"fade",parallaxBackgroundImage:"",parallaxBackgroundSize:"",parallaxBackgroundRepeat:"",parallaxBackgroundPosition:"",parallaxBackgroundHorizontal:null,parallaxBackgroundVertical:null,pdfMaxPagesPerSlide:Number.POSITIVE_INFINITY,pdfSeparateFragments:!0,pdfPageHeightOffset:-1,viewDistance:3,mobileViewDistance:2,display:"block",hideInactiveCursor:!0,hideCursorTime:5e3,dependencies:[]},i=function(e,t){let a;const i=navigator.userAgent,o=/registerPlugin|registerKeyboardShortcut|addKeyBinding|addEventListener/;let s,l,d,c,u,p,f,h,g,m,v=!1,b=!1,y=null,w=null,A=!1,k=!1,E=[],S=1,L={layout:"",overview:""},x={},M={},N=[],q={},I=0,P=0,T=!1,C=0,O=!1,R=0,D=0,B=0,H=-1,z=!1,j={startX:0,startY:0,startCount:0,captured:!1,threshold:40},$={},W={};function F(){let e=Object.keys(M).length;if(0===e)U();else{let t=()=>{0==--e&&U()};for(let e in M){let a=M[e];if("function"==typeof a.init){let e=a.init();e&&"funLine truncated
|
||||
!function(e){var t={};function a(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,a),r.l=!0,r.exports}a.m=e,a.c=t,a.d=function(e,t,n){a.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,t){if(1&t&&(e=a(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(a.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)a.d(n,r,function(t){return e[t]}.bind(null,r));return n},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="",a(a.s=0)}([function(e,t,a){"use strict";a.r(t);class n{constructor(e,t){this.diameter=100,this.diameter2=this.diameter/2,this.thickness=6,this.playing=!1,this.progress=0,this.progressOffset=1,this.container=e,this.progressCheck=t,this.canvas=document.createElement("canvas"),this.canvas.className="playback",this.canvas.width=this.diameter,this.canvas.height=this.diameter,this.canvas.style.width=this.diameter2+"px",this.canvas.style.height=this.diameter2+"px",this.context=this.canvas.getContext("2d"),this.container.appendChild(this.canvas),this.render()}setPlaying(e){const t=this.playing;this.playing=e,!t&&this.playing?this.animate():this.render()}animate(){const e=this.progress;this.progress=this.progressCheck(),e>.8&&this.progress<.2&&(this.progressOffset=this.progress),this.render(),this.playing&&requestAnimationFrame(this.animate.bind(this))}render(){let e=this.playing?this.progress:0,t=this.diameter2-this.thickness,a=this.diameter2,n=this.diameter2;this.progressOffset+=.1*(1-this.progressOffset);const r=-Math.PI/2+e*(2*Math.PI),i=-Math.PI/2+this.progressOffset*(2*Math.PI);this.context.save(),this.context.clearRect(0,0,this.diameter,this.diameter),this.context.beginPath(),this.context.arc(a,n,t+4,0,2*Math.PI,!1),this.context.fillStyle="rgba( 0, 0, 0, 0.4 )",this.context.fill(),this.context.beginPath(),this.context.arc(a,n,t,0,2*Math.PI,!1),this.context.lineWidth=this.thickness,this.context.strokeStyle="rgba( 255, 255, 255, 0.2 )",this.context.stroke(),this.playing&&(this.context.beginPath(),this.context.arc(a,n,t,i,r,!1),this.context.lineWidth=this.thickness,this.context.strokeStyle="#fff",this.context.stroke()),this.context.translate(a-14,n-14),this.playing?(this.context.fillStyle="#fff",this.context.fillRect(0,0,10,28),this.context.fillRect(18,0,10,28)):(this.context.beginPath(),this.context.translate(4,0),this.context.moveTo(0,0),this.context.lineTo(24,14),this.context.lineTo(0,28),this.context.fillStyle="#fff",this.context.fill()),this.context.restore()}on(e,t){this.canvas.addEventListener(e,t,!1)}off(e,t){this.canvas.removeEventListener(e,t,!1)}destroy(){this.playing=!1,this.canvas.parentNode&&this.container.removeChild(this.canvas)}}var r={width:960,height:700,margin:.04,minScale:.2,maxScale:2,controls:!0,controlsTutorial:!0,controlsLayout:"bottom-right",controlsBackArrows:"faded",progress:!0,slideNumber:!1,showSlideNumber:"all",hashOneBasedIndex:!1,hash:!1,history:!1,keyboard:!0,keyboardCondition:null,overview:!0,disableLayout:!1,center:!0,touch:!0,loop:!1,rtl:!1,navigationMode:"default",shuffle:!1,fragments:!0,fragmentInURL:!1,embedded:!1,help:!0,pause:!0,showNotes:!1,autoPlayMedia:null,preloadIframes:null,autoAnimate:!0,autoAnimateMatcher:null,autoAnimateEasing:"ease",autoAnimateDuration:1,autoAnimateUnmatched:!0,autoAnimateStyles:["opacity","color","background-color","padding","font-size","line-height","letter-spacing","border-width","border-color","border-radius","outline","outline-offset"],autoSlide:0,autoSlideStoppable:!0,autoSlideMethod:null,defaultTiming:null,mouseWheel:!1,previewLinks:!1,postMessage:!0,postMessageEvents:!1,focusBodyOnPageVisibilityChange:!0,transition:"slide",transitionSpeed:"default",backgroundTransition:"fade",parallaxBackgroundImage:"",parallaxBackgroundSize:"",parallaxBackgroundRepeat:"",parallaxBackgroundPosition:"",parallaxBackgroundHorizontal:null,parallaxBackgroundVertical:null,pdfMaxPagesPerSlide:Number.POSITIVE_INFINITY,pdfSeparateFragments:!0,pdfPageHeightOffset:-1,viewDistance:3,mobileViewDistance:2,display:"block",hideInactiveCursor:!0,hideCursorTime:5e3,dependencies:[]};const i=e=>Array.prototype.slice.call(e);function o(e,t){if(s(),autoAnimateStyleSheet&&autoAnimateStyleSheet.parentNode&&(autoAnimateStyleSheet.parentNode.removeChild(autoAnimateStyleSheet),autoAnimateStyleSheet=null),e.hasAttribute("data-auto-animate")&&t.hasAttribute("data-auto-animate")){autoAnimateStyleSheet=autoAnimateStyleSheet||document.createElement("style"),autoAnimateStyleSheet.type="text/css",document.head.appendChild(autoAnimateStyleSheet);let a=l(t);e.dataset.autoAnimate="pending",t.dataset.autoALine truncated
|
||||
+23
-268
@@ -1,5 +1,17 @@
|
||||
import Playback from './components/playback.js'
|
||||
import defaultConfig from './config.js'
|
||||
import {
|
||||
extend,
|
||||
toArray,
|
||||
distanceBetween,
|
||||
deserialize,
|
||||
transformElement,
|
||||
injectStyleSheet,
|
||||
closestParent,
|
||||
colorToRgb,
|
||||
colorBrightness,
|
||||
enterFullscreen
|
||||
} from './utils/util.js'
|
||||
|
||||
/**
|
||||
* reveal.js
|
||||
@@ -1350,84 +1362,6 @@ export default function( revealElement, options ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend object a with the properties of object b.
|
||||
* If there's a conflict, object b takes precedence.
|
||||
*
|
||||
* @param {object} a
|
||||
* @param {object} b
|
||||
*/
|
||||
function extend( a, b ) {
|
||||
|
||||
for( var i in b ) {
|
||||
a[ i ] = b[ i ];
|
||||
}
|
||||
|
||||
return a;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the target object to an array.
|
||||
*
|
||||
* @param {object} o
|
||||
* @return {object[]}
|
||||
*/
|
||||
function toArray( o ) {
|
||||
|
||||
return Array.prototype.slice.call( o );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility for deserializing a value.
|
||||
*
|
||||
* @param {*} value
|
||||
* @return {*}
|
||||
*/
|
||||
function deserialize( value ) {
|
||||
|
||||
if( typeof value === 'string' ) {
|
||||
if( value === 'null' ) return null;
|
||||
else if( value === 'true' ) return true;
|
||||
else if( value === 'false' ) return false;
|
||||
else if( value.match( /^-?[\d\.]+$/ ) ) return parseFloat( value );
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Measures the distance in pixels between point a
|
||||
* and point b.
|
||||
*
|
||||
* @param {object} a point with x/y properties
|
||||
* @param {object} b point with x/y properties
|
||||
*
|
||||
* @return {number}
|
||||
*/
|
||||
function distanceBetween( a, b ) {
|
||||
|
||||
var dx = a.x - b.x,
|
||||
dy = a.y - b.y;
|
||||
|
||||
return Math.sqrt( dx*dx + dy*dy );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a CSS transform to the target element.
|
||||
*
|
||||
* @param {HTMLElement} element
|
||||
* @param {string} transform
|
||||
*/
|
||||
function transformElement( element, transform ) {
|
||||
|
||||
element.style.transform = transform;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies CSS transforms to the slides container. The container
|
||||
* is transformed from two separate sources: layout and the overview
|
||||
@@ -1451,139 +1385,6 @@ export default function( revealElement, options ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Injects the given CSS styles into the DOM.
|
||||
*
|
||||
* @param {string} value
|
||||
*/
|
||||
function injectStyleSheet( value ) {
|
||||
|
||||
let tag = document.createElement( 'style' );
|
||||
tag.type = 'text/css';
|
||||
if( tag.styleSheet ) {
|
||||
tag.styleSheet.cssText = value;
|
||||
}
|
||||
else {
|
||||
tag.appendChild( document.createTextNode( value ) );
|
||||
}
|
||||
document.getElementsByTagName( 'head' )[0].appendChild( tag );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the closest parent that matches the given
|
||||
* selector.
|
||||
*
|
||||
* @param {HTMLElement} target The child element
|
||||
* @param {String} selector The CSS selector to match
|
||||
* the parents against
|
||||
*
|
||||
* @return {HTMLElement} The matched parent or null
|
||||
* if no matching parent was found
|
||||
*/
|
||||
function closestParent( target, selector ) {
|
||||
|
||||
let parent = target.parentNode;
|
||||
|
||||
while( parent ) {
|
||||
|
||||
// There's some overhead doing this each time, we don't
|
||||
// want to rewrite the element prototype but should still
|
||||
// be enough to feature detect once at startup...
|
||||
let matchesMethod = parent.matches || parent.matchesSelector || parent.msMatchesSelector;
|
||||
|
||||
// If we find a match, we're all set
|
||||
if( matchesMethod && matchesMethod.call( parent, selector ) ) {
|
||||
return parent;
|
||||
}
|
||||
|
||||
// Keep searching
|
||||
parent = parent.parentNode;
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts various color input formats to an {r:0,g:0,b:0} object.
|
||||
*
|
||||
* @param {string} color The string representation of a color
|
||||
* @example
|
||||
* colorToRgb('#000');
|
||||
* @example
|
||||
* colorToRgb('#000000');
|
||||
* @example
|
||||
* colorToRgb('rgb(0,0,0)');
|
||||
* @example
|
||||
* colorToRgb('rgba(0,0,0)');
|
||||
*
|
||||
* @return {{r: number, g: number, b: number, [a]: number}|null}
|
||||
*/
|
||||
function colorToRgb( color ) {
|
||||
|
||||
let hex3 = color.match( /^#([0-9a-f]{3})$/i );
|
||||
if( hex3 && hex3[1] ) {
|
||||
hex3 = hex3[1];
|
||||
return {
|
||||
r: parseInt( hex3.charAt( 0 ), 16 ) * 0x11,
|
||||
g: parseInt( hex3.charAt( 1 ), 16 ) * 0x11,
|
||||
b: parseInt( hex3.charAt( 2 ), 16 ) * 0x11
|
||||
};
|
||||
}
|
||||
|
||||
let hex6 = color.match( /^#([0-9a-f]{6})$/i );
|
||||
if( hex6 && hex6[1] ) {
|
||||
hex6 = hex6[1];
|
||||
return {
|
||||
r: parseInt( hex6.substr( 0, 2 ), 16 ),
|
||||
g: parseInt( hex6.substr( 2, 2 ), 16 ),
|
||||
b: parseInt( hex6.substr( 4, 2 ), 16 )
|
||||
};
|
||||
}
|
||||
|
||||
let rgb = color.match( /^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i );
|
||||
if( rgb ) {
|
||||
return {
|
||||
r: parseInt( rgb[1], 10 ),
|
||||
g: parseInt( rgb[2], 10 ),
|
||||
b: parseInt( rgb[3], 10 )
|
||||
};
|
||||
}
|
||||
|
||||
let rgba = color.match( /^rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\,\s*([\d]+|[\d]*.[\d]+)\s*\)$/i );
|
||||
if( rgba ) {
|
||||
return {
|
||||
r: parseInt( rgba[1], 10 ),
|
||||
g: parseInt( rgba[2], 10 ),
|
||||
b: parseInt( rgba[3], 10 ),
|
||||
a: parseFloat( rgba[4] )
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates brightness on a scale of 0-255.
|
||||
*
|
||||
* @param {string} color See colorToRgb for supported formats.
|
||||
* @see {@link colorToRgb}
|
||||
*/
|
||||
function colorBrightness( color ) {
|
||||
|
||||
if( typeof color === 'string' ) color = colorToRgb( color );
|
||||
|
||||
if( color ) {
|
||||
return ( color.r * 299 + color.g * 587 + color.b * 114 ) / 1000;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the remaining height within the parent of the
|
||||
* target element.
|
||||
@@ -2293,29 +2094,6 @@ export default function( revealElement, options ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handling the fullscreen functionality via the fullscreen API
|
||||
*
|
||||
* @see http://fullscreen.spec.whatwg.org/
|
||||
* @see https://developer.mozilla.org/en-US/docs/DOM/Using_fullscreen_mode
|
||||
*/
|
||||
function enterFullscreen() {
|
||||
|
||||
let element = document.documentElement;
|
||||
|
||||
// Check which implementation is available
|
||||
let requestMethod = element.requestFullscreen ||
|
||||
element.webkitRequestFullscreen ||
|
||||
element.webkitRequestFullScreen ||
|
||||
element.mozRequestFullScreen ||
|
||||
element.msRequestFullscreen;
|
||||
|
||||
if( requestMethod ) {
|
||||
requestMethod.apply( element );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the mouse pointer after it has been hidden with
|
||||
* #hideCursor.
|
||||
@@ -4541,6 +4319,7 @@ export default function( revealElement, options ) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the h/v location and fragment of the current,
|
||||
* or specified, slide.
|
||||
@@ -6015,24 +5794,16 @@ export default function( revealElement, options ) {
|
||||
getComputedSlideSize,
|
||||
|
||||
// Returns the previous slide element, may be null
|
||||
getPreviousSlide: () => {
|
||||
return previousSlide;
|
||||
},
|
||||
getPreviousSlide: () => previousSlide,
|
||||
|
||||
// Returns the current slide element
|
||||
getCurrentSlide: () => {
|
||||
return currentSlide;
|
||||
},
|
||||
getCurrentSlide: () => currentSlide,
|
||||
|
||||
// Returns the current scale of the presentation content
|
||||
getScale: () => {
|
||||
return scale;
|
||||
},
|
||||
getScale: () => scale,
|
||||
|
||||
// Returns the current configuration object
|
||||
getConfig: () => {
|
||||
return config;
|
||||
},
|
||||
getConfig: () => config,
|
||||
|
||||
// Helper method, retrieves query string as a key/value hash
|
||||
getQueryHash: () => {
|
||||
@@ -6053,19 +5824,13 @@ export default function( revealElement, options ) {
|
||||
},
|
||||
|
||||
// Returns the top-level DOM element
|
||||
getRevealElement: () => {
|
||||
return dom.wrapper || document.querySelector( '.reveal' );
|
||||
},
|
||||
getRevealElement: () => dom.wrapper || document.querySelector( '.reveal' ),
|
||||
|
||||
// Returns a hash with all registered plugins
|
||||
getPlugins: () => {
|
||||
return plugins;
|
||||
},
|
||||
getPlugins: () => plugins,
|
||||
|
||||
// Returns true if we're currently on the first slide
|
||||
isFirstSlide: () => {
|
||||
return indexh === 0 && indexv === 0;
|
||||
},
|
||||
isFirstSlide: () => indexh === 0 && indexv === 0,
|
||||
|
||||
// Returns true if we're currently on the last slide
|
||||
isLastSlide: () => {
|
||||
@@ -6096,31 +5861,21 @@ export default function( revealElement, options ) {
|
||||
},
|
||||
|
||||
// Checks if reveal.js has been loaded and is ready for use
|
||||
isReady: () => {
|
||||
return loaded;
|
||||
},
|
||||
isReady: () => loaded,
|
||||
|
||||
// Forward event binding to the reveal DOM element
|
||||
addEventListener: ( type, listener, useCapture ) => {
|
||||
if( 'addEventListener' in window ) {
|
||||
Reveal.getRevealElement().addEventListener( type, listener, useCapture );
|
||||
}
|
||||
},
|
||||
removeEventListener: ( type, listener, useCapture ) => {
|
||||
if( 'addEventListener' in window ) {
|
||||
Reveal.getRevealElement().removeEventListener( type, listener, useCapture );
|
||||
}
|
||||
},
|
||||
|
||||
// Programmatically triggers a keyboard event
|
||||
triggerKey: keyCode => {
|
||||
onDocumentKeyDown( { keyCode } );
|
||||
},
|
||||
triggerKey: keyCode => onDocumentKeyDown( { keyCode } ),
|
||||
|
||||
// Registers a new shortcut to include in the help overlay
|
||||
registerKeyboardShortcut: ( key, value ) => {
|
||||
keyboardShortcuts[key] = value;
|
||||
}
|
||||
registerKeyboardShortcut: ( key, value ) => keyboardShortcuts[key] = value
|
||||
};
|
||||
|
||||
return init();
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
/**
|
||||
* Extend object a with the properties of object b.
|
||||
* If there's a conflict, object b takes precedence.
|
||||
*
|
||||
* @param {object} a
|
||||
* @param {object} b
|
||||
*/
|
||||
export const extend = ( a, b ) => {
|
||||
|
||||
for( var i in b ) {
|
||||
a[ i ] = b[ i ];
|
||||
}
|
||||
|
||||
return a;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the target object to an array.
|
||||
*
|
||||
* @param {object} o
|
||||
* @return {object[]}
|
||||
*/
|
||||
export const toArray = ( o ) => {
|
||||
|
||||
return Array.prototype.slice.call( o );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility for deserializing a value.
|
||||
*
|
||||
* @param {*} value
|
||||
* @return {*}
|
||||
*/
|
||||
export const deserialize = ( value ) => {
|
||||
|
||||
if( typeof value === 'string' ) {
|
||||
if( value === 'null' ) return null;
|
||||
else if( value === 'true' ) return true;
|
||||
else if( value === 'false' ) return false;
|
||||
else if( value.match( /^-?[\d\.]+$/ ) ) return parseFloat( value );
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Measures the distance in pixels between point a
|
||||
* and point b.
|
||||
*
|
||||
* @param {object} a point with x/y properties
|
||||
* @param {object} b point with x/y properties
|
||||
*
|
||||
* @return {number}
|
||||
*/
|
||||
export const distanceBetween = ( a, b ) => {
|
||||
|
||||
var dx = a.x - b.x,
|
||||
dy = a.y - b.y;
|
||||
|
||||
return Math.sqrt( dx*dx + dy*dy );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a CSS transform to the target element.
|
||||
*
|
||||
* @param {HTMLElement} element
|
||||
* @param {string} transform
|
||||
*/
|
||||
export const transformElement = ( element, transform ) => {
|
||||
|
||||
element.style.transform = transform;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Injects the given CSS styles into the DOM.
|
||||
*
|
||||
* @param {string} value
|
||||
*/
|
||||
export const injectStyleSheet = ( value ) => {
|
||||
|
||||
let tag = document.createElement( 'style' );
|
||||
tag.type = 'text/css';
|
||||
if( tag.styleSheet ) {
|
||||
tag.styleSheet.cssText = value;
|
||||
}
|
||||
else {
|
||||
tag.appendChild( document.createTextNode( value ) );
|
||||
}
|
||||
document.getElementsByTagName( 'head' )[0].appendChild( tag );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the closest parent that matches the given
|
||||
* selector.
|
||||
*
|
||||
* @param {HTMLElement} target The child element
|
||||
* @param {String} selector The CSS selector to match
|
||||
* the parents against
|
||||
*
|
||||
* @return {HTMLElement} The matched parent or null
|
||||
* if no matching parent was found
|
||||
*/
|
||||
export const closestParent = ( target, selector ) => {
|
||||
|
||||
let parent = target.parentNode;
|
||||
|
||||
while( parent ) {
|
||||
|
||||
// There's some overhead doing this each time, we don't
|
||||
// want to rewrite the element prototype but should still
|
||||
// be enough to feature detect once at startup...
|
||||
let matchesMethod = parent.matches || parent.matchesSelector || parent.msMatchesSelector;
|
||||
|
||||
// If we find a match, we're all set
|
||||
if( matchesMethod && matchesMethod.call( parent, selector ) ) {
|
||||
return parent;
|
||||
}
|
||||
|
||||
// Keep searching
|
||||
parent = parent.parentNode;
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts various color input formats to an {r:0,g:0,b:0} object.
|
||||
*
|
||||
* @param {string} color The string representation of a color
|
||||
* @example
|
||||
* colorToRgb('#000');
|
||||
* @example
|
||||
* colorToRgb('#000000');
|
||||
* @example
|
||||
* colorToRgb('rgb(0,0,0)');
|
||||
* @example
|
||||
* colorToRgb('rgba(0,0,0)');
|
||||
*
|
||||
* @return {{r: number, g: number, b: number, [a]: number}|null}
|
||||
*/
|
||||
export const colorToRgb = ( color ) => {
|
||||
|
||||
let hex3 = color.match( /^#([0-9a-f]{3})$/i );
|
||||
if( hex3 && hex3[1] ) {
|
||||
hex3 = hex3[1];
|
||||
return {
|
||||
r: parseInt( hex3.charAt( 0 ), 16 ) * 0x11,
|
||||
g: parseInt( hex3.charAt( 1 ), 16 ) * 0x11,
|
||||
b: parseInt( hex3.charAt( 2 ), 16 ) * 0x11
|
||||
};
|
||||
}
|
||||
|
||||
let hex6 = color.match( /^#([0-9a-f]{6})$/i );
|
||||
if( hex6 && hex6[1] ) {
|
||||
hex6 = hex6[1];
|
||||
return {
|
||||
r: parseInt( hex6.substr( 0, 2 ), 16 ),
|
||||
g: parseInt( hex6.substr( 2, 2 ), 16 ),
|
||||
b: parseInt( hex6.substr( 4, 2 ), 16 )
|
||||
};
|
||||
}
|
||||
|
||||
let rgb = color.match( /^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i );
|
||||
if( rgb ) {
|
||||
return {
|
||||
r: parseInt( rgb[1], 10 ),
|
||||
g: parseInt( rgb[2], 10 ),
|
||||
b: parseInt( rgb[3], 10 )
|
||||
};
|
||||
}
|
||||
|
||||
let rgba = color.match( /^rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\,\s*([\d]+|[\d]*.[\d]+)\s*\)$/i );
|
||||
if( rgba ) {
|
||||
return {
|
||||
r: parseInt( rgba[1], 10 ),
|
||||
g: parseInt( rgba[2], 10 ),
|
||||
b: parseInt( rgba[3], 10 ),
|
||||
a: parseFloat( rgba[4] )
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates brightness on a scale of 0-255.
|
||||
*
|
||||
* @param {string} color See colorToRgb for supported formats.
|
||||
* @see {@link colorToRgb}
|
||||
*/
|
||||
export const colorBrightness = ( color ) => {
|
||||
|
||||
if( typeof color === 'string' ) color = colorToRgb( color );
|
||||
|
||||
if( color ) {
|
||||
return ( color.r * 299 + color.g * 587 + color.b * 114 ) / 1000;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handling the fullscreen functionality via the fullscreen API
|
||||
*
|
||||
* @see http://fullscreen.spec.whatwg.org/
|
||||
* @see https://developer.mozilla.org/en-US/docs/DOM/Using_fullscreen_mode
|
||||
*/
|
||||
export const enterFullscreen = () => {
|
||||
|
||||
let element = document.documentElement;
|
||||
|
||||
// Check which implementation is available
|
||||
let requestMethod = element.requestFullscreen ||
|
||||
element.webkitRequestFullscreen ||
|
||||
element.webkitRequestFullScreen ||
|
||||
element.mozRequestFullScreen ||
|
||||
element.msRequestFullscreen;
|
||||
|
||||
if( requestMethod ) {
|
||||
requestMethod.apply( element );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user