File size: 1,064 Bytes
aa3b624
3833190
 
 
66a740c
6770eb3
3833190
aa3b624
 
 
 
 
66a740c
 
 
 
 
aa3b624
66a740c
 
 
 
aa3b624
 
3833190
 
aa3b624
 
 
66a740c
 
 
 
aa3b624
 
 
 
3833190
aa3b624
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { destroyStage } from "./stage";
import { destroyEvents, initEvents } from "./events";
import { Config, configure, getConfig } from "./config";
import { destroyHighlight, highlight } from "./highlight";

import "./style.css";
import { destroyHooks, register } from "./hooks";

export type DriveStep = {
  element?: string | Element;
};

export function driver(options: Config = {}) {
  configure(options);

  const shouldAnimate = getConfig("animate");

  function init() {
    document.body.classList.add(
      "driver-active",
      shouldAnimate ? "driver-fade" : "driver-simple"
    );

    initEvents();

    register("overlayClick", destroy);
  }

  function destroy() {
    document.body.classList.remove(
      "driver-active",
      shouldAnimate ? "driver-fade" : "driver-simple"
    );

    destroyEvents();
    destroyHighlight();
    destroyStage();
    destroyHooks();
  }

  return {
    drive: (steps: DriveStep[]) => console.log(steps),
    highlight: (step: DriveStep) => {
      init();
      highlight(step);
    },
    destroy,
  };
}