UNPKG

28.3 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { Directive, inject, Injectable, InjectionToken, NgZone } from '@angular/core';
9import { fromEvent, Subject } from 'rxjs';
10import { filter, takeUntil } from 'rxjs/operators';
11import { throwMissingMenuReference, throwMissingPointerFocusTracker } from './menu-errors';
12import * as i0 from "@angular/core";
13/** Injection token used for an implementation of MenuAim. */
14export const MENU_AIM = new InjectionToken('cdk-menu-aim');
15/** Capture every nth mouse move event. */
16const MOUSE_MOVE_SAMPLE_FREQUENCY = 3;
17/** The number of mouse move events to track. */
18const NUM_POINTS = 5;
19/**
20 * How long to wait before closing a sibling menu if a user stops short of the submenu they were
21 * predicted to go into.
22 */
23const CLOSE_DELAY = 300;
24/** Calculate the slope between point a and b. */
25function getSlope(a, b) {
26 return (b.y - a.y) / (b.x - a.x);
27}
28/** Calculate the y intercept for the given point and slope. */
29function getYIntercept(point, slope) {
30 return point.y - slope * point.x;
31}
32/**
33 * Whether the given mouse trajectory line defined by the slope and y intercept falls within the
34 * submenu as defined by `submenuPoints`
35 * @param submenuPoints the submenu DOMRect points.
36 * @param m the slope of the trajectory line.
37 * @param b the y intercept of the trajectory line.
38 * @return true if any point on the line falls within the submenu.
39 */
40function isWithinSubmenu(submenuPoints, m, b) {
41 const { left, right, top, bottom } = submenuPoints;
42 // Check for intersection with each edge of the submenu (left, right, top, bottom)
43 // by fixing one coordinate to that edge's coordinate (either x or y) and checking if the
44 // other coordinate is within bounds.
45 return ((m * left + b >= top && m * left + b <= bottom) ||
46 (m * right + b >= top && m * right + b <= bottom) ||
47 ((top - b) / m >= left && (top - b) / m <= right) ||
48 ((bottom - b) / m >= left && (bottom - b) / m <= right));
49}
50/**
51 * TargetMenuAim predicts if a user is moving into a submenu. It calculates the
52 * trajectory of the user's mouse movement in the current menu to determine if the
53 * mouse is moving towards an open submenu.
54 *
55 * The determination is made by calculating the slope of the users last NUM_POINTS moves where each
56 * pair of points determines if the trajectory line points into the submenu. It uses consensus
57 * approach by checking if at least NUM_POINTS / 2 pairs determine that the user is moving towards
58 * to submenu.
59 */
60class TargetMenuAim {
61 constructor() {
62 /** The Angular zone. */
63 this._ngZone = inject(NgZone);
64 /** The last NUM_POINTS mouse move events. */
65 this._points = [];
66 /** Emits when this service is destroyed. */
67 this._destroyed = new Subject();
68 }
69 ngOnDestroy() {
70 this._destroyed.next();
71 this._destroyed.complete();
72 }
73 /**
74 * Set the Menu and its PointerFocusTracker.
75 * @param menu The menu that this menu aim service controls.
76 * @param pointerTracker The `PointerFocusTracker` for the given menu.
77 */
78 initialize(menu, pointerTracker) {
79 this._menu = menu;
80 this._pointerTracker = pointerTracker;
81 this._subscribeToMouseMoves();
82 }
83 /**
84 * Calls the `doToggle` callback when it is deemed that the user is not moving towards
85 * the submenu.
86 * @param doToggle the function called when the user is not moving towards the submenu.
87 */
88 toggle(doToggle) {
89 // If the menu is horizontal the sub-menus open below and there is no risk of premature
90 // closing of any sub-menus therefore we automatically resolve the callback.
91 if (this._menu.orientation === 'horizontal') {
92 doToggle();
93 }
94 this._checkConfigured();
95 const siblingItemIsWaiting = !!this._timeoutId;
96 const hasPoints = this._points.length > 1;
97 if (hasPoints && !siblingItemIsWaiting) {
98 if (this._isMovingToSubmenu()) {
99 this._startTimeout(doToggle);
100 }
101 else {
102 doToggle();
103 }
104 }
105 else if (!siblingItemIsWaiting) {
106 doToggle();
107 }
108 }
109 /**
110 * Start the delayed toggle handler if one isn't running already.
111 *
112 * The delayed toggle handler executes the `doToggle` callback after some period of time iff the
113 * users mouse is on an item in the current menu.
114 *
115 * @param doToggle the function called when the user is not moving towards the submenu.
116 */
117 _startTimeout(doToggle) {
118 // If the users mouse is moving towards a submenu we don't want to immediately resolve.
119 // Wait for some period of time before determining if the previous menu should close in
120 // cases where the user may have moved towards the submenu but stopped on a sibling menu
121 // item intentionally.
122 const timeoutId = setTimeout(() => {
123 // Resolve if the user is currently moused over some element in the root menu
124 if (this._pointerTracker.activeElement && timeoutId === this._timeoutId) {
125 doToggle();
126 }
127 this._timeoutId = null;
128 }, CLOSE_DELAY);
129 this._timeoutId = timeoutId;
130 }
131 /** Whether the user is heading towards the open submenu. */
132 _isMovingToSubmenu() {
133 const submenuPoints = this._getSubmenuBounds();
134 if (!submenuPoints) {
135 return false;
136 }
137 let numMoving = 0;
138 const currPoint = this._points[this._points.length - 1];
139 // start from the second last point and calculate the slope between each point and the last
140 // point.
141 for (let i = this._points.length - 2; i >= 0; i--) {
142 const previous = this._points[i];
143 const slope = getSlope(currPoint, previous);
144 if (isWithinSubmenu(submenuPoints, slope, getYIntercept(currPoint, slope))) {
145 numMoving++;
146 }
147 }
148 return numMoving >= Math.floor(NUM_POINTS / 2);
149 }
150 /** Get the bounding DOMRect for the open submenu. */
151 _getSubmenuBounds() {
152 return this._pointerTracker?.previousElement?.getMenu()?.nativeElement.getBoundingClientRect();
153 }
154 /**
155 * Check if a reference to the PointerFocusTracker and menu element is provided.
156 * @throws an error if neither reference is provided.
157 */
158 _checkConfigured() {
159 if (typeof ngDevMode === 'undefined' || ngDevMode) {
160 if (!this._pointerTracker) {
161 throwMissingPointerFocusTracker();
162 }
163 if (!this._menu) {
164 throwMissingMenuReference();
165 }
166 }
167 }
168 /** Subscribe to the root menus mouse move events and update the tracked mouse points. */
169 _subscribeToMouseMoves() {
170 this._ngZone.runOutsideAngular(() => {
171 fromEvent(this._menu.nativeElement, 'mousemove')
172 .pipe(filter((_, index) => index % MOUSE_MOVE_SAMPLE_FREQUENCY === 0), takeUntil(this._destroyed))
173 .subscribe((event) => {
174 this._points.push({ x: event.clientX, y: event.clientY });
175 if (this._points.length > NUM_POINTS) {
176 this._points.shift();
177 }
178 });
179 });
180 }
181 static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: TargetMenuAim, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
182 static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: TargetMenuAim }); }
183}
184export { TargetMenuAim };
185i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: TargetMenuAim, decorators: [{
186 type: Injectable
187 }] });
188/**
189 * CdkTargetMenuAim is a provider for the TargetMenuAim service. It can be added to an
190 * element with either the `cdkMenu` or `cdkMenuBar` directive and child menu items.
191 */
192class CdkTargetMenuAim {
193 static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: CdkTargetMenuAim, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
194 static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.0.0", type: CdkTargetMenuAim, isStandalone: true, selector: "[cdkTargetMenuAim]", providers: [{ provide: MENU_AIM, useClass: TargetMenuAim }], exportAs: ["cdkTargetMenuAim"], ngImport: i0 }); }
195}
196export { CdkTargetMenuAim };
197i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: CdkTargetMenuAim, decorators: [{
198 type: Directive,
199 args: [{
200 selector: '[cdkTargetMenuAim]',
201 exportAs: 'cdkTargetMenuAim',
202 standalone: true,
203 providers: [{ provide: MENU_AIM, useClass: TargetMenuAim }],
204 }]
205 }] });
206//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVudS1haW0uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvY2RrL21lbnUvbWVudS1haW0udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUgsT0FBTyxFQUFDLFNBQVMsRUFBRSxNQUFNLEVBQUUsVUFBVSxFQUFFLGNBQWMsRUFBRSxNQUFNLEVBQVksTU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