index.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { Config } from './config.ts';
  2. //@ts-ignore
  3. import Deck, { VERSION } from './reveal.js';
  4. /**
  5. * Expose the Reveal class to the window. To create a
  6. * new instance:
  7. * let deck = new Reveal( document.querySelector( '.reveal' ), {
  8. * controls: false
  9. * } );
  10. * deck.initialize().then(() => {
  11. * // reveal.js is ready
  12. * });
  13. */
  14. const Reveal: {
  15. initialize: (options?: Config) => Promise<void>;
  16. [key: string]: any;
  17. } = Deck;
  18. /**
  19. * The below is a thin shell that mimics the pre 4.0
  20. * reveal.js API and ensures backwards compatibility.
  21. * This API only allows for one Reveal instance per
  22. * page, whereas the new API above lets you run many
  23. * presentations on the same page.
  24. *
  25. * Reveal.initialize( { controls: false } ).then(() => {
  26. * // reveal.js is ready
  27. * });
  28. */
  29. type RevealApiFunction = (...args: any[]) => any;
  30. const enqueuedAPICalls: RevealApiFunction[] = [];
  31. Reveal.initialize = (options?: Config) => {
  32. // Create our singleton reveal.js instance
  33. Object.assign(Reveal, new Deck(document.querySelector('.reveal'), options));
  34. // Invoke any enqueued API calls
  35. enqueuedAPICalls.map((method) => method(Reveal));
  36. return Reveal.initialize();
  37. };
  38. /**
  39. * The pre 4.0 API let you add event listener before
  40. * initializing. We maintain the same behavior by
  41. * queuing up premature API calls and invoking all
  42. * of them when Reveal.initialize is called.
  43. */
  44. ['configure', 'on', 'off', 'addEventListener', 'removeEventListener', 'registerPlugin'].forEach(
  45. (method) => {
  46. Reveal[method] = (...args: any) => {
  47. enqueuedAPICalls.push((deck) => deck[method].call(null, ...args));
  48. };
  49. }
  50. );
  51. Reveal.isReady = () => false;
  52. Reveal.VERSION = VERSION;
  53. export default Reveal;