返回 reveal.js
reveal.d.ts
根目录 / dist / reveal.d.ts
1 import { RevealConfig, TransitionStyle, TransitionSpeed, FragmentAnimation, KatexConfig, Mathjax2Config, Mathjax3Config, Mathjax4Config, HighlightConfig, MarkdownConfig } from './config';
2 export type {
3 RevealConfig,
4 TransitionStyle,
5 TransitionSpeed,
6 FragmentAnimation,
7 KatexConfig,
8 Mathjax2Config,
9 Mathjax3Config,
10 Mathjax4Config,
11 HighlightConfig,
12 MarkdownConfig,
13 } from './config';
14
15 export default Reveal;
16
17 // The type definitions in this file are adapted from those
18 // originally created by the community on DefinitelyTyped:
19 // https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/reveal.js
20
21 /**
22 * reveal.js - MIT licensed
23 *
24 * Copyright (C) 2011-2026 Hakim El Hattab, https://hakim.se
25 *
26 * @see {@link https://revealjs.com}
27 * @see {@link https://github.com/hakimel/reveal.js/blob/master/js/reveal.js}
28 * @see {@link https://revealjs.com/api/}
29 */
30 declare const Reveal: {
31 new (options?: RevealConfig): RevealApi;
32 new (revealElement: HTMLElement, options?: RevealConfig): RevealApi;
33 } & RevealApi;
34
35 /**
36 * The public reveal.js API
37 *
38 * @see {@link https://github.com/hakimel/reveal.js/blob/master/js/reveal.js}
39 */
40 export interface RevealApi {
41 /**
42 * The reveal.js version
43 *
44 * @returns reveal.js version
45 */
46 VERSION: string;
47
48 /**
49 * Starts up the presentation.
50 *
51 * @param options - RevealOption see {@link Options}
52 * @returns a promise
53 */
54 initialize(options?: RevealConfig): Promise<RevealApi>;
55
56 /**
57 * Applies the configuration settings from the config
58 * object. May be called multiple times.
59 *
60 * @param options - RevealOption see {@link RevealConfig}
61 */
62 configure(options?: RevealConfig): void;
63
64 /**
65 * Uninitializes reveal.js by undoing changes made to the
66 * DOM and removing all event listeners.
67 */
68 destroy(): void;
69
70 /**
71 * Syncs the presentation with the current DOM. Useful
72 * when new slides or control elements are added or when
73 * the configuration has changed.
74 */
75 sync(): void;
76
77 /**
78 * Updates reveal.js to keep in sync with new slide attributes. For
79 * example, if you add a new `data-background-image` you can call
80 * this to have reveal.js render the new background image.
81 *
82 * Similar to #sync() but more efficient when you only need to
83 * refresh a specific slide. Dispatches a `slidesync` event
84 * when syncing has completed.
85 *
86 * @param slide
87 * @see {@link sync}
88 */
89 syncSlide(slide: HTMLElement): void;
90
91 /**
92 * Formats the fragments on the given slide so that they have
93 * valid indices. Call this if fragments are changed in the DOM
94 * after reveal.js has already initialized.
95 *
96 * @param slide
97 * @returns a list of the HTML fragments that were synced
98 */
99 syncFragments(slide: HTMLElement): HTMLElement[];
100
101 /**
102 * Removes hidden slides (data-visibility="hidden") from the DOM.
103 * This happens automatically when reveal.js initialized, so only
104 * call this to remove hidden slides before initialization.
105 */
106 removeHiddenSlides(): void;
107
108 /**
109 * Steps from the current point in the presentation to the
110 * slide which matches the specified horizontal and vertical
111 * indices.
112 *
113 * @param horizontalIndex - Horizontal index of the target slide
114 * @param verticalIndex - Vertical index of the target slide
115 * @param fragmentIndex - Index of a fragment within the target slide to activate
116 * @param origin - Origin for use in multimaster environments
117 */
118 slide(
119 horizontalIndex?: number,
120 verticalIndex?: number,
121 fragmentIndex?: number,
122 origin?: number
123 ): void;
124
125 /**
126 * Navigate one step to the left
127 *
128 * @param params see {@link NavigateParams}
129 */
130 left: NavigationFunction;
131
132 /**
133 * Navigate one step to the right
134 *
135 * @param params see {@link NavigateParams}
136 */
137 right: NavigationFunction;
138
139 /**
140 * Navigate one step up
141 *
142 * @param params see {@link NavigateParams}
143 */
144 up: NavigationFunction;
145
146 /**
147 * Navigate one step down
148 *
149 * @param params see {@link NavigateParams}
150 */
151 down: NavigationFunction;
152
153 /**
154 * Navigates backwards, prioritized in the following order:
155 * 1) Previous fragment
156 * 2) Previous vertical slide
157 * 3) Previous horizontal slide
158 *
159 * @param params see {@link NavigateParams}
160 */
161 prev: NavigationFunction;
162
163 /**
164 * Navigates forwards, prioritized in the following order:
165 * 1) Next fragment
166 * 2) Next vertical slide
167 * 3) Next horizontal slide
168 *
169 * @param params see {@link NavigateParams}
170 */
171 next: NavigationFunction;
172
173 // Navigation aliases
174
175 /**
176 * Alias for `left` see {@link left}
177 */
178 navigateLeft: NavigationFunction;
179
180 /**
181 * Alias for `right` see {@link right}
182 */
183 navigateRight: NavigationFunction;
184
185 /**
186 * Alias for `up` see {@link up}
187 */
188 navigateUp: NavigationFunction;
189
190 /**
191 * Alias for `down` see {@link down}
192 */
193 navigateDown: NavigationFunction;
194
195 /**
196 * Alias for `prev` see {@link prev}
197 */
198 navigatePrev: NavigationFunction;
199
200 /**
201 * Alias for `next` see {@link next}
202 */
203 navigateNext: NavigationFunction;
204
205 /**
206 * Navigate to the specified slide fragment.
207 *
208 * @param index - The index of the fragment that
209 * should be shown, -1 means all are invisible
210 * @param offset - Integer offset to apply to the
211 * fragment index
212 *
213 * @returns true if a change was made in any
214 * fragments visibility as part of this call
215 */
216 navigateFragment(index?: number, offset?: number): boolean;
217
218 /**
219 * Navigate to the previous slide fragment.
220 *
221 * @returns true if there was a previous fragment,
222 * false otherwise
223 */
224 prevFragment(): boolean;
225
226 /**
227 * Navigate to the next slide fragment.
228 *
229 * @returns true if there was a next fragment,
230 * false otherwise
231 */
232 nextFragment(): boolean;
233
234 /**
235 * Adds a listener to one of our custom reveal.js events,
236 * like slidechanged and slidesync.
237 *
238 * @param type
239 * @param listener
240 * @param useCapture
241 */
242 on: HTMLElement['addEventListener'];
243
244 /**
245 * Unsubscribes from a reveal.js event.
246 *
247 * @param type
248 * @param listener
249 * @param useCapture
250 */
251 off: HTMLElement['removeEventListener'];
252
253 /**
254 * Legacy event binding methods left in for backwards compatibility
255 * Adds a listener to one of our custom reveal.js events,
256 * like slidechanged and slidesync.
257 * See: {@link on}
258 *
259 * @param type
260 * @param listener
261 * @param useCapture
262 */
263 addEventListener: HTMLElement['addEventListener'];
264
265 /**
266 * Legacy event binding methods left in for backwards compatibility
267 * Unsubscribes from a reveal.js event.
268 * See: {@link off}
269 *
270 * @param type
271 * @param listener
272 * @param useCapture
273 */
274 removeEventListener: HTMLElement['removeEventListener'];
275
276 /**
277 * Applies JavaScript-controlled layout rules to the
278 * presentation.
279 */
280 layout(): void;
281
282 /**
283 * Randomly shuffles all slides in the deck.
284 */
285 shuffle(slides?: HTMLElement[]): void;
286
287 /**
288 * Determine what available routes there are for navigation.
289 *
290 * @param params - If includeFragments is set, a route will be considered
291 * available if either a slide OR a fragment is available in the given direction
292 *
293 * @returns Available route {left, right, up, down}
294 */
295 availableRoutes(params?: { includeFragments?: boolean }): {
296 down: boolean;
297 left: boolean;
298 right: boolean;
299 up: boolean;
300 };
301
302 /**
303 * Returns an object describing the available fragment
304 * directions.
305 *
306 * @returns Available fragments {prev, next}
307 */
308 availableFragments(): { prev: boolean; next: boolean };
309
310 /**
311 * Open or close help overlay window.
312 *
313 * @param override - Flag which overrides the
314 * toggle logic and forcibly sets the desired state. True means
315 * help is open, false means it's closed.
316 */
317 toggleHelp(override?: boolean): void;
318
319 /**
320 * Toggles the slide overview mode on and off.
321 *
322 * @param override - Flag which overrides the
323 * toggle logic and forcibly sets the desired state. True means
324 * overview is open, false means it's closed.
325 */
326 toggleOverview(override?: boolean): void;
327
328 /**
329 * Toggles the paused mode on and off.
330 *
331 * @param override - Flag which overrides the
332 * toggle logic and forcibly sets the desired state.
333 */
334 togglePause(override?: boolean): void;
335
336 /**
337 * Toggles the auto slide mode on and off.
338 *
339 * @param override - Flag which sets the desired state.
340 * True means autoplay starts, false means it stops.
341 */
342 toggleAutoSlide(override?: boolean): void;
343
344 /**
345 * @returns true if we're currently on the first slide in
346 * the presentation.
347 */
348 isFirstSlide(): boolean;
349
350 /**
351 * @returns Returns true if we're currently on the last slide in
352 * the presentation. If the last slide is a stack, we only
353 * consider this the last slide if it's at the end of the
354 * stack.
355 */
356 isLastSlide(): boolean;
357
358 /**
359 * @returns true if we're on the last slide in the current
360 * vertical stack.
361 */
362 isLastVerticalSlide(): boolean;
363
364 /**
365 * Checks if the current or specified slide is vertical
366 * (nested within another slide).
367 *
368 * @param slide - the slide to check orientation of. Defaults to the current slide.
369 * @return true if the current or specified slide is vertical
370 */
371 isVerticalSlide(slide?: HTMLElement): boolean;
372
373 /**
374 * @returns true if we are currently in the paused mode.
375 */
376 isPaused(): boolean;
377
378 /**
379 * @returns true if the auto slide mode is currently on.
380 */
381 isAutoSliding(): boolean;
382
383 /**
384 * @returns true if this presentation is running inside of
385 * the speaker notes window.
386 */
387 isSpeakerNotes(): boolean;
388
389 /**
390 * @returns true if the overview is active, false otherwise
391 */
392 isOverview(): boolean;
393
394 /**
395 * Checks if the presentation is focused
396 *
397 * @returns true if the it is focused, false otherwise
398 */
399 isFocused(): boolean;
400
401 /**
402 * Checks if this reveal.js instance is being used to print a PDF.
403 *
404 * @returns true if being used to print a PDF, false otherwise
405 */
406 isPrintingPDF(): boolean;
407
408 /**
409 * Checks if reveal.js has been loaded and is ready for use
410 *
411 * @returns true if reveal.js is ready for use, false otherwise
412 */
413 isReady(): boolean;
414
415 /**
416 * Called when the given slide is within the configured view
417 * distance. Shows the slide element and loads any content
418 * that is set to load lazily (data-src).
419 *
420 * @param slide - Slide to show
421 */
422 loadSlide(slide: HTMLElement, options?: { excludeIframes?: boolean }): void;
423
424 /**
425 * Unloads and hides the given slide. This is called when the
426 * slide is moved outside of the configured view distance.
427 *
428 * @param slide
429 */
430 unloadSlide(slide: HTMLElement): void;
431
432 /**
433 * Opens a preview window for the target URL.
434 *
435 * @param url - url for preview iframe src
436 */
437 showPreview(url: string): void;
438
439 /**
440 * Closes any currently open overlay.
441 */
442 hidePreview(): void;
443
444 /**
445 * Binds all internal event listeners.
446 */
447 addEventListeners(): void;
448
449 /**
450 * Unbinds all internal event listeners.
451 */
452 removeEventListeners(): void;
453
454 /**
455 * Dispatches an event of the specified type from the
456 * reveal DOM element.
457 */
458 dispatchEvent({
459 target,
460 type,
461 data,
462 bubbles,
463 }: {
464 /** `revealElement` by default */
465 target?: HTMLElement;
466 type: string;
467 data?: unknown;
468 bubbles?: boolean;
469 }): Event;
470
471 /**
472 * Retrieves the current state of the presentation as
473 * an object. This state can then be restored at any
474 * time.
475 *
476 * @returns The current state - {indexh, indexv, indexf, paused, overview}
477 */
478 getState(): RevealState;
479
480 /**
481 * Restores the presentation to the given state.
482 *
483 * @param object - state as generated by getState()
484 * @see {@link getState} generates the parameter `state`
485 */
486 setState(object: RevealState): void;
487
488 /**
489 * Returns a value ranging from 0-1 that represents
490 * how far into the presentation we have navigated.
491 *
492 * @returns a value ranging from 0-1 that represents
493 * how far into the presentation we have navigated.
494 */
495 getProgress(): number;
496
497 /**
498 * Retrieves the h/v location and fragment of the current,
499 * or specified, slide.
500 *
501 * @param slide - if specified, the returned index will
502 * be for this slide rather than the currently active one
503 *
504 * @return h/v location and fragment of the current,
505 * or specified, slide. {h, v, f}
506 */
507 getIndices(slide?: HTMLElement): { h: number; v: number; f: number };
508
509 /**
510 * Returns an array of objects where each object represents the
511 * attributes on its respective slide.
512 *
513 * @returns an array of objects where each object represents the
514 * attributes on its respective slide.
515 */
516 getSlidesAttributes(): Record<string, string>[];
517
518 /**
519 * Returns the number of past slides. This can be used as a global
520 * flattened index for slides.
521 *
522 * @param [slide] - The slide we're counting before, defaults to current slide
523 *
524 * @returns Past slide count
525 */
526 getSlidePastCount(slide?: HTMLElement): number;
527
528 /**
529 * Retrieves the total number of slides in this presentation.
530 *
531 * @returns the total number of slides in this presentation.
532 */
533 getTotalSlides(): number;
534
535 /**
536 * Returns the slide element matching the specified index.
537 *
538 * @param x - slide index
539 * @param [y] - slide index
540 *
541 * @returns the slide element matching the specified index
542 */
543 getSlide(x: number, y?: number): HTMLElement | undefined;
544
545 /**
546 * Returns the previous slide element, may be null
547 *
548 * @returns the previous slide element, may be null
549 */
550 getPreviousSlide(): HTMLElement | null;
551
552 /**
553 * Returns the current slide element
554 *
555 * @returns the current slide element
556 */
557 getCurrentSlide(): HTMLElement;
558
559 /**
560 * Returns the background element for the given slide.
561 * All slides, even the ones with no background properties
562 * defined, have a background element so as long as the
563 * index is valid an element will be returned.
564 *
565 * @param element A slide
566 * @returns the background element for the given slide
567 */
568 getSlideBackground(element: HTMLElement): HTMLElement | undefined;
569
570 /**
571 * Returns the background element for the given slide.
572 * All slides, even the ones with no background properties
573 * defined, have a background element so as long as the
574 * index is valid an element will be returned.
575 *
576 * @param x - Horizontal background index OR a slide
577 * HTML element
578 * @param [y] - Vertical background index
579 * @returns the background element for the given slide
580 */
581 getSlideBackground(x: number, y?: number): HTMLElement | undefined;
582
583 /**
584 * Retrieves the speaker notes from a slide. Notes can be
585 * defined in two ways:
586 * 1. As a data-notes attribute on the slide <section>
587 * 2. As an <aside class="notes"> inside of the slide
588 *
589 * @param [slide] - defaults to current slide
590 * @returns the speaker notes from a slide
591 */
592 getSlideNotes(slide?: HTMLElement): string | null;
593
594 /**
595 * Retrieves all slides in this presentation.
596 *
597 * @returns all slides in this presentation
598 */
599 getSlides(): HTMLElement[];
600
601 /**
602 * Returns a list of all horizontal slides in the deck. Each
603 * vertical stack is included as one horizontal slide in the
604 * resulting array.
605 *
606 * @returns a list of all horizontal slides in the deck
607 */
608 getHorizontalSlides(): HTMLElement[];
609
610 /**
611 * Returns all vertical slides that exist within this deck.
612 *
613 * @returns all vertical slides that exist within this deck
614 */
615 getVerticalSlides(): HTMLElement[];
616
617 /**
618 * Returns true if there are at least two horizontal slides.
619 *
620 * @returns true if there are at least two horizontal slides
621 */
622 hasHorizontalSlides(): boolean;
623
624 /**
625 * Returns true if there are at least two vertical slides.
626 *
627 * @returns true if there are at least two vertical slides
628 */
629 hasVerticalSlides(): boolean;
630
631 /**
632 * Checks if the deck has navigated on either axis at least once
633 *
634 * @returns true if the deck has navigated on either horizontal axis
635 * at least once
636 */
637 hasNavigatedHorizontally(): boolean;
638
639 /**
640 * Checks if the deck has navigated on either axis at least once
641 *
642 * @returns true if the deck has navigated on either vertically axis
643 * at least once
644 */
645 hasNavigatedVertically(): boolean;
646
647 /**
648 * Add a custom key binding with optional description to
649 * be added to the help screen.
650 *
651 * @param binding
652 * @param callback
653 */
654 addKeyBinding(
655 keyCode: number | { keyCode: number; key: string; description: string },
656 callback: string | ((event: KeyboardEvent) => void)
657 ): void;
658
659 /**
660 * Removes the specified custom key binding.
661 *
662 * @param keyCode
663 */
664 removeKeyBinding(keyCode: number): void;
665
666 /**
667 * Programmatically triggers a keyboard event
668 *
669 * @param keyCode
670 */
671 triggerKey(keyCode: number): void;
672
673 /**
674 * Registers a new shortcut to include in the help overlay
675 *
676 * @param key
677 * @param value
678 */
679 registerKeyboardShortcut(key: string, value: string): void;
680
681 /**
682 * Calculates the computed pixel size of our slides. These
683 * values are based on the width and height configuration
684 * options.
685 *
686 * @param [presentationWidth=dom.wrapper.offsetWidth]
687 * @param [presentationHeight=dom.wrapper.offsetHeight]
688 * @returns the computed pixel size of the slides
689 */
690 getComputedSlideSize(
691 presentationWidth?: number,
692 presentationHeight?: number
693 ): ComputedSlideSize;
694
695 /**
696 * Returns the current scale of the presentation content
697 *
698 * @returns the current scale of the presentation content
699 */
700 getScale(): number;
701
702 /**
703 * Returns the current configuration object
704 *
705 * @returns the current configuration object
706 */
707 getConfig(): RevealConfig;
708
709 /**
710 * Returns a key:value hash of all query params.
711 *
712 * @returns a key:value hash of all query params
713 */
714 getQueryHash(): Record<string, string>;
715
716 /**
717 * Return a hash URL that will resolve to the given slide location.
718 *
719 * @param slide - the slide to link to
720 * @returns a hash URL that will resolve to the given slide location
721 */
722 getSlidePath(slide?: HTMLElement): string;
723
724 /**
725 * @returns reveal.js DOM element
726 */
727 getRevealElement(): HTMLElement | null;
728
729 /**
730 * @returns reveal.js DOM element
731 */
732 getSlidesElement(): HTMLElement | null;
733
734 /**
735 * @returns reveal.js DOM element
736 */
737 getViewportElement(): HTMLElement | null;
738
739 /**
740 * @returns reveal.js DOM element
741 */
742 getBackgroundsElement(): HTMLDivElement | undefined;
743
744 /**
745 * Registers a new plugin with this reveal.js instance.
746 *
747 * reveal.js waits for all registered plugins to initialize
748 * before considering itself ready, as long as the plugin
749 * is registered before calling `Reveal.initialize()`.
750 *
751 * @param plugin
752 */
753 registerPlugin(plugin: RevealPlugin): void;
754
755 /**
756 * Checks if a specific plugin has been registered.
757 *
758 * @param id - unique plugin identifier
759 * @returns true if a specific plugin has been registered.
760 */
761 hasPlugin(id: string): boolean;
762
763 /**
764 * Returns the specific plugin instance, if a plugin
765 * with the given ID has been registered.
766 *
767 * @param id - unique plugin identifier
768 * @returns plugin instance
769 */
770 getPlugin(id: string): RevealPlugin | undefined;
771
772 /**
773 * @returns id:plugin hash of all plugins
774 */
775 getPlugins(): Record<string, RevealPlugin>;
776 }
777
778 /**
779 * Options for navigation
780 */
781 export interface NavigateParams {
782 skipFragments?: boolean;
783 }
784
785 export type NavigationFunction = (params?: NavigateParams) => void;
786
787 /**
788 * Multiplex configuration
789 *
790 * @see {@link https://github.com/reveal/multiplex}
791 */
792 export interface MultiplexConfig {
793 // Obtained from the socket.io server. Gives this (the master) control of the presentation
794 secret: string | null;
795 // Obtained from the socket.io server
796 id: string;
797 // Location of socket.io server
798 url: string;
799 }
800
801 /**
802 * Reveal Dependency
803 *
804 * @see {@link https://revealjs.com/plugins/#dependencies}
805 */
806 export interface RevealDependency {
807 src: string;
808 async?: boolean;
809 callback?: () => void;
810 condition?: () => boolean;
811 }
812
813 export interface ComputedSlideSize {
814 width: number;
815 height: number;
816 presentationWidth: number;
817 presentationHeight: number;
818 }
819
820 export interface RevealState {
821 indexh: number;
822 indexv: number;
823 indexf: number;
824 paused: boolean;
825 overview: boolean;
826
827 /**
828 * URL of an iframe being previewed
829 */
830 previewIframe?: string;
831
832 /**
833 * URL of an image being previewed
834 */
835 previewImage?: string;
836
837 /**
838 * URL of a video being previewed
839 */
840 previewVideo?: string;
841
842 /**
843 * Fit mode of the previewed media
844 */
845 previewFit?: 'none' | 'scale-down' | 'contain' | 'cover';
846 }
847
848 export interface SlideSyncEvent extends Event {
849 slide: HTMLElement;
850 }
851
852 // NOTE: it is possible to extend type definitions depend on the plugin
853 /**
854 * Reveal Plugin
855 *
856 * @see {@link https://revealjs.com/creating-plugins/}
857 */
858 export interface RevealPlugin {
859 id: string;
860 init?(reveal: RevealApi): void | Promise<void>;
861 destroy?(): void;
862 }
863
864 export type RevealPluginFactory = () => RevealPlugin;
865
865 lines TYPESCRIPT