UNPKG

1.91 kBPlain TextView Raw
1import type {
2 AngleRange,
3 TouchBackendContext,
4 TouchBackendOptions,
5} from './interfaces.js'
6
7export class OptionsReader implements TouchBackendOptions {
8 public constructor(
9 private args: Partial<TouchBackendOptions>,
10 private context: TouchBackendContext,
11 ) {}
12
13 public get delay(): number {
14 return this.args.delay ?? 0
15 }
16
17 public get scrollAngleRanges(): AngleRange[] | undefined {
18 return this.args.scrollAngleRanges
19 }
20
21 public get getDropTargetElementsAtPoint():
22 | ((x: number, y: number, elements: HTMLElement[]) => HTMLElement[])
23 | undefined {
24 return this.args.getDropTargetElementsAtPoint
25 }
26
27 public get ignoreContextMenu(): boolean {
28 return this.args.ignoreContextMenu ?? false
29 }
30
31 public get enableHoverOutsideTarget(): boolean {
32 return this.args.enableHoverOutsideTarget ?? false
33 }
34
35 public get enableKeyboardEvents(): boolean {
36 return this.args.enableKeyboardEvents ?? false
37 }
38
39 public get enableMouseEvents(): boolean {
40 return this.args.enableMouseEvents ?? false
41 }
42
43 public get enableTouchEvents(): boolean {
44 return this.args.enableTouchEvents ?? true
45 }
46
47 public get touchSlop(): number {
48 return this.args.touchSlop || 0
49 }
50
51 public get delayTouchStart(): number {
52 return this.args?.delayTouchStart ?? this.args?.delay ?? 0
53 }
54
55 public get delayMouseStart(): number {
56 return this.args?.delayMouseStart ?? this.args?.delay ?? 0
57 }
58
59 public get window(): Window | undefined {
60 if (this.context && this.context.window) {
61 return this.context.window
62 } else if (typeof window !== 'undefined') {
63 return window
64 }
65 return undefined
66 }
67
68 public get document(): Document | undefined {
69 if (this.context?.document) {
70 return this.context.document
71 }
72
73 if (this.window) {
74 return this.window.document
75 }
76
77 return undefined
78 }
79
80 public get rootElement(): Node | undefined {
81 return this.args?.rootElement || (this.document as any as Node)
82 }
83}
84
\No newline at end of file