source: trip-planner-front/node_modules/@angular/cdk/fesm2015/overlay.js@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 133.0 KB
Line 
1import * as i1 from '@angular/cdk/scrolling';
2import { ScrollDispatcher, ViewportRuler, ScrollingModule } from '@angular/cdk/scrolling';
3export { CdkScrollable, ScrollDispatcher, ViewportRuler } from '@angular/cdk/scrolling';
4import * as i1$1 from '@angular/common';
5import { DOCUMENT, Location } from '@angular/common';
6import * as i0 from '@angular/core';
7import { Injectable, NgZone, Inject, Optional, ElementRef, ApplicationRef, ComponentFactoryResolver, Injector, InjectionToken, Directive, EventEmitter, TemplateRef, ViewContainerRef, Input, Output, NgModule } from '@angular/core';
8import { coerceCssPixelValue, coerceArray, coerceBooleanProperty } from '@angular/cdk/coercion';
9import * as i2 from '@angular/cdk/platform';
10import { supportsScrollBehavior, _getEventTarget, Platform, _isTestEnvironment } from '@angular/cdk/platform';
11import { Directionality, BidiModule } from '@angular/cdk/bidi';
12import { DomPortalOutlet, TemplatePortal, PortalModule } from '@angular/cdk/portal';
13import { Subject, Subscription, merge } from 'rxjs';
14import { take, takeUntil, takeWhile } from 'rxjs/operators';
15import { ESCAPE, hasModifierKey } from '@angular/cdk/keycodes';
16
17/**
18 * @license
19 * Copyright Google LLC All Rights Reserved.
20 *
21 * Use of this source code is governed by an MIT-style license that can be
22 * found in the LICENSE file at https://angular.io/license
23 */
24const scrollBehaviorSupported = supportsScrollBehavior();
25/**
26 * Strategy that will prevent the user from scrolling while the overlay is visible.
27 */
28class BlockScrollStrategy {
29 constructor(_viewportRuler, document) {
30 this._viewportRuler = _viewportRuler;
31 this._previousHTMLStyles = { top: '', left: '' };
32 this._isEnabled = false;
33 this._document = document;
34 }
35 /** Attaches this scroll strategy to an overlay. */
36 attach() { }
37 /** Blocks page-level scroll while the attached overlay is open. */
38 enable() {
39 if (this._canBeEnabled()) {
40 const root = this._document.documentElement;
41 this._previousScrollPosition = this._viewportRuler.getViewportScrollPosition();
42 // Cache the previous inline styles in case the user had set them.
43 this._previousHTMLStyles.left = root.style.left || '';
44 this._previousHTMLStyles.top = root.style.top || '';
45 // Note: we're using the `html` node, instead of the `body`, because the `body` may
46 // have the user agent margin, whereas the `html` is guaranteed not to have one.
47 root.style.left = coerceCssPixelValue(-this._previousScrollPosition.left);
48 root.style.top = coerceCssPixelValue(-this._previousScrollPosition.top);
49 root.classList.add('cdk-global-scrollblock');
50 this._isEnabled = true;
51 }
52 }
53 /** Unblocks page-level scroll while the attached overlay is open. */
54 disable() {
55 if (this._isEnabled) {
56 const html = this._document.documentElement;
57 const body = this._document.body;
58 const htmlStyle = html.style;
59 const bodyStyle = body.style;
60 const previousHtmlScrollBehavior = htmlStyle.scrollBehavior || '';
61 const previousBodyScrollBehavior = bodyStyle.scrollBehavior || '';
62 this._isEnabled = false;
63 htmlStyle.left = this._previousHTMLStyles.left;
64 htmlStyle.top = this._previousHTMLStyles.top;
65 html.classList.remove('cdk-global-scrollblock');
66 // Disable user-defined smooth scrolling temporarily while we restore the scroll position.
67 // See https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-behavior
68 // Note that we don't mutate the property if the browser doesn't support `scroll-behavior`,
69 // because it can throw off feature detections in `supportsScrollBehavior` which
70 // checks for `'scrollBehavior' in documentElement.style`.
71 if (scrollBehaviorSupported) {
72 htmlStyle.scrollBehavior = bodyStyle.scrollBehavior = 'auto';
73 }
74 window.scroll(this._previousScrollPosition.left, this._previousScrollPosition.top);
75 if (scrollBehaviorSupported) {
76 htmlStyle.scrollBehavior = previousHtmlScrollBehavior;
77 bodyStyle.scrollBehavior = previousBodyScrollBehavior;
78 }
79 }
80 }
81 _canBeEnabled() {
82 // Since the scroll strategies can't be singletons, we have to use a global CSS class
83 // (`cdk-global-scrollblock`) to make sure that we don't try to disable global
84 // scrolling multiple times.
85 const html = this._document.documentElement;
86 if (html.classList.contains('cdk-global-scrollblock') || this._isEnabled) {
87 return false;
88 }
89 const body = this._document.body;
90 const viewport = this._viewportRuler.getViewportSize();
91 return body.scrollHeight > viewport.height || body.scrollWidth > viewport.width;
92 }
93}
94
95/**
96 * @license
97 * Copyright Google LLC All Rights Reserved.
98 *
99 * Use of this source code is governed by an MIT-style license that can be
100 * found in the LICENSE file at https://angular.io/license
101 */
102/**
103 * Returns an error to be thrown when attempting to attach an already-attached scroll strategy.
104 */
105function getMatScrollStrategyAlreadyAttachedError() {
106 return Error(`Scroll strategy has already been attached.`);
107}
108
109/**
110 * Strategy that will close the overlay as soon as the user starts scrolling.
111 */
112class CloseScrollStrategy {
113 constructor(_scrollDispatcher, _ngZone, _viewportRuler, _config) {
114 this._scrollDispatcher = _scrollDispatcher;
115 this._ngZone = _ngZone;
116 this._viewportRuler = _viewportRuler;
117 this._config = _config;
118 this._scrollSubscription = null;
119 /** Detaches the overlay ref and disables the scroll strategy. */
120 this._detach = () => {
121 this.disable();
122 if (this._overlayRef.hasAttached()) {
123 this._ngZone.run(() => this._overlayRef.detach());
124 }
125 };
126 }
127 /** Attaches this scroll strategy to an overlay. */
128 attach(overlayRef) {
129 if (this._overlayRef && (typeof ngDevMode === 'undefined' || ngDevMode)) {
130 throw getMatScrollStrategyAlreadyAttachedError();
131 }
132 this._overlayRef = overlayRef;
133 }
134 /** Enables the closing of the attached overlay on scroll. */
135 enable() {
136 if (this._scrollSubscription) {
137 return;
138 }
139 const stream = this._scrollDispatcher.scrolled(0);
140 if (this._config && this._config.threshold && this._config.threshold > 1) {
141 this._initialScrollPosition = this._viewportRuler.getViewportScrollPosition().top;
142 this._scrollSubscription = stream.subscribe(() => {
143 const scrollPosition = this._viewportRuler.getViewportScrollPosition().top;
144 if (Math.abs(scrollPosition - this._initialScrollPosition) > this._config.threshold) {
145 this._detach();
146 }
147 else {
148 this._overlayRef.updatePosition();
149 }
150 });
151 }
152 else {
153 this._scrollSubscription = stream.subscribe(this._detach);
154 }
155 }
156 /** Disables the closing the attached overlay on scroll. */
157 disable() {
158 if (this._scrollSubscription) {
159 this._scrollSubscription.unsubscribe();
160 this._scrollSubscription = null;
161 }
162 }
163 detach() {
164 this.disable();
165 this._overlayRef = null;
166 }
167}
168
169/**
170 * @license
171 * Copyright Google LLC All Rights Reserved.
172 *
173 * Use of this source code is governed by an MIT-style license that can be
174 * found in the LICENSE file at https://angular.io/license
175 */
176/** Scroll strategy that doesn't do anything. */
177class NoopScrollStrategy {
178 /** Does nothing, as this scroll strategy is a no-op. */
179 enable() { }
180 /** Does nothing, as this scroll strategy is a no-op. */
181 disable() { }
182 /** Does nothing, as this scroll strategy is a no-op. */
183 attach() { }
184}
185
186/**
187 * @license
188 * Copyright Google LLC All Rights Reserved.
189 *
190 * Use of this source code is governed by an MIT-style license that can be
191 * found in the LICENSE file at https://angular.io/license
192 */
193// TODO(jelbourn): move this to live with the rest of the scrolling code
194// TODO(jelbourn): someday replace this with IntersectionObservers
195/**
196 * Gets whether an element is scrolled outside of view by any of its parent scrolling containers.
197 * @param element Dimensions of the element (from getBoundingClientRect)
198 * @param scrollContainers Dimensions of element's scrolling containers (from getBoundingClientRect)
199 * @returns Whether the element is scrolled out of view
200 * @docs-private
201 */
202function isElementScrolledOutsideView(element, scrollContainers) {
203 return scrollContainers.some(containerBounds => {
204 const outsideAbove = element.bottom < containerBounds.top;
205 const outsideBelow = element.top > containerBounds.bottom;
206 const outsideLeft = element.right < containerBounds.left;
207 const outsideRight = element.left > containerBounds.right;
208 return outsideAbove || outsideBelow || outsideLeft || outsideRight;
209 });
210}
211/**
212 * Gets whether an element is clipped by any of its scrolling containers.
213 * @param element Dimensions of the element (from getBoundingClientRect)
214 * @param scrollContainers Dimensions of element's scrolling containers (from getBoundingClientRect)
215 * @returns Whether the element is clipped
216 * @docs-private
217 */
218function isElementClippedByScrolling(element, scrollContainers) {
219 return scrollContainers.some(scrollContainerRect => {
220 const clippedAbove = element.top < scrollContainerRect.top;
221 const clippedBelow = element.bottom > scrollContainerRect.bottom;
222 const clippedLeft = element.left < scrollContainerRect.left;
223 const clippedRight = element.right > scrollContainerRect.right;
224 return clippedAbove || clippedBelow || clippedLeft || clippedRight;
225 });
226}
227
228/**
229 * @license
230 * Copyright Google LLC All Rights Reserved.
231 *
232 * Use of this source code is governed by an MIT-style license that can be
233 * found in the LICENSE file at https://angular.io/license
234 */
235/**
236 * Strategy that will update the element position as the user is scrolling.
237 */
238class RepositionScrollStrategy {
239 constructor(_scrollDispatcher, _viewportRuler, _ngZone, _config) {
240 this._scrollDispatcher = _scrollDispatcher;
241 this._viewportRuler = _viewportRuler;
242 this._ngZone = _ngZone;
243 this._config = _config;
244 this._scrollSubscription = null;
245 }
246 /** Attaches this scroll strategy to an overlay. */
247 attach(overlayRef) {
248 if (this._overlayRef && (typeof ngDevMode === 'undefined' || ngDevMode)) {
249 throw getMatScrollStrategyAlreadyAttachedError();
250 }
251 this._overlayRef = overlayRef;
252 }
253 /** Enables repositioning of the attached overlay on scroll. */
254 enable() {
255 if (!this._scrollSubscription) {
256 const throttle = this._config ? this._config.scrollThrottle : 0;
257 this._scrollSubscription = this._scrollDispatcher.scrolled(throttle).subscribe(() => {
258 this._overlayRef.updatePosition();
259 // TODO(crisbeto): make `close` on by default once all components can handle it.
260 if (this._config && this._config.autoClose) {
261 const overlayRect = this._overlayRef.overlayElement.getBoundingClientRect();
262 const { width, height } = this._viewportRuler.getViewportSize();
263 // TODO(crisbeto): include all ancestor scroll containers here once
264 // we have a way of exposing the trigger element to the scroll strategy.
265 const parentRects = [{ width, height, bottom: height, right: width, top: 0, left: 0 }];
266 if (isElementScrolledOutsideView(overlayRect, parentRects)) {
267 this.disable();
268 this._ngZone.run(() => this._overlayRef.detach());
269 }
270 }
271 });
272 }
273 }
274 /** Disables repositioning of the attached overlay on scroll. */
275 disable() {
276 if (this._scrollSubscription) {
277 this._scrollSubscription.unsubscribe();
278 this._scrollSubscription = null;
279 }
280 }
281 detach() {
282 this.disable();
283 this._overlayRef = null;
284 }
285}
286
287/**
288 * @license
289 * Copyright Google LLC All Rights Reserved.
290 *
291 * Use of this source code is governed by an MIT-style license that can be
292 * found in the LICENSE file at https://angular.io/license
293 */
294/**
295 * Options for how an overlay will handle scrolling.
296 *
297 * Users can provide a custom value for `ScrollStrategyOptions` to replace the default
298 * behaviors. This class primarily acts as a factory for ScrollStrategy instances.
299 */
300class ScrollStrategyOptions {
301 constructor(_scrollDispatcher, _viewportRuler, _ngZone, document) {
302 this._scrollDispatcher = _scrollDispatcher;
303 this._viewportRuler = _viewportRuler;
304 this._ngZone = _ngZone;
305 /** Do nothing on scroll. */
306 this.noop = () => new NoopScrollStrategy();
307 /**
308 * Close the overlay as soon as the user scrolls.
309 * @param config Configuration to be used inside the scroll strategy.
310 */
311 this.close = (config) => new CloseScrollStrategy(this._scrollDispatcher, this._ngZone, this._viewportRuler, config);
312 /** Block scrolling. */
313 this.block = () => new BlockScrollStrategy(this._viewportRuler, this._document);
314 /**
315 * Update the overlay's position on scroll.
316 * @param config Configuration to be used inside the scroll strategy.
317 * Allows debouncing the reposition calls.
318 */
319 this.reposition = (config) => new RepositionScrollStrategy(this._scrollDispatcher, this._viewportRuler, this._ngZone, config);
320 this._document = document;
321 }
322}
323ScrollStrategyOptions.ɵprov = i0.ɵɵdefineInjectable({ factory: function ScrollStrategyOptions_Factory() { return new ScrollStrategyOptions(i0.ɵɵinject(i1.ScrollDispatcher), i0.ɵɵinject(i1.ViewportRuler), i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(i1$1.DOCUMENT)); }, token: ScrollStrategyOptions, providedIn: "root" });
324ScrollStrategyOptions.decorators = [
325 { type: Injectable, args: [{ providedIn: 'root' },] }
326];
327ScrollStrategyOptions.ctorParameters = () => [
328 { type: ScrollDispatcher },
329 { type: ViewportRuler },
330 { type: NgZone },
331 { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] }
332];
333
334/**
335 * @license
336 * Copyright Google LLC All Rights Reserved.
337 *
338 * Use of this source code is governed by an MIT-style license that can be
339 * found in the LICENSE file at https://angular.io/license
340 */
341
342/**
343 * @license
344 * Copyright Google LLC All Rights Reserved.
345 *
346 * Use of this source code is governed by an MIT-style license that can be
347 * found in the LICENSE file at https://angular.io/license
348 */
349/** Initial configuration used when creating an overlay. */
350class OverlayConfig {
351 constructor(config) {
352 /** Strategy to be used when handling scroll events while the overlay is open. */
353 this.scrollStrategy = new NoopScrollStrategy();
354 /** Custom class to add to the overlay pane. */
355 this.panelClass = '';
356 /** Whether the overlay has a backdrop. */
357 this.hasBackdrop = false;
358 /** Custom class to add to the backdrop */
359 this.backdropClass = 'cdk-overlay-dark-backdrop';
360 /**
361 * Whether the overlay should be disposed of when the user goes backwards/forwards in history.
362 * Note that this usually doesn't include clicking on links (unless the user is using
363 * the `HashLocationStrategy`).
364 */
365 this.disposeOnNavigation = false;
366 if (config) {
367 // Use `Iterable` instead of `Array` because TypeScript, as of 3.6.3,
368 // loses the array generic type in the `for of`. But we *also* have to use `Array` because
369 // typescript won't iterate over an `Iterable` unless you compile with `--downlevelIteration`
370 const configKeys = Object.keys(config);
371 for (const key of configKeys) {
372 if (config[key] !== undefined) {
373 // TypeScript, as of version 3.5, sees the left-hand-side of this expression
374 // as "I don't know *which* key this is, so the only valid value is the intersection
375 // of all the posible values." In this case, that happens to be `undefined`. TypeScript
376 // is not smart enough to see that the right-hand-side is actually an access of the same
377 // exact type with the same exact key, meaning that the value type must be identical.
378 // So we use `any` to work around this.
379 this[key] = config[key];
380 }
381 }
382 }
383 }
384}
385
386/**
387 * @license
388 * Copyright Google LLC All Rights Reserved.
389 *
390 * Use of this source code is governed by an MIT-style license that can be
391 * found in the LICENSE file at https://angular.io/license
392 */
393/** The points of the origin element and the overlay element to connect. */
394class ConnectionPositionPair {
395 constructor(origin, overlay,
396 /** Offset along the X axis. */
397 offsetX,
398 /** Offset along the Y axis. */
399 offsetY,
400 /** Class(es) to be applied to the panel while this position is active. */
401 panelClass) {
402 this.offsetX = offsetX;
403 this.offsetY = offsetY;
404 this.panelClass = panelClass;
405 this.originX = origin.originX;
406 this.originY = origin.originY;
407 this.overlayX = overlay.overlayX;
408 this.overlayY = overlay.overlayY;
409 }
410}
411/**
412 * Set of properties regarding the position of the origin and overlay relative to the viewport
413 * with respect to the containing Scrollable elements.
414 *
415 * The overlay and origin are clipped if any part of their bounding client rectangle exceeds the
416 * bounds of any one of the strategy's Scrollable's bounding client rectangle.
417 *
418 * The overlay and origin are outside view if there is no overlap between their bounding client
419 * rectangle and any one of the strategy's Scrollable's bounding client rectangle.
420 *
421 * ----------- -----------
422 * | outside | | clipped |
423 * | view | --------------------------
424 * | | | | | |
425 * ---------- | ----------- |
426 * -------------------------- | |
427 * | | | Scrollable |
428 * | | | |
429 * | | --------------------------
430 * | Scrollable |
431 * | |
432 * --------------------------
433 *
434 * @docs-private
435 */
436class ScrollingVisibility {
437}
438/** The change event emitted by the strategy when a fallback position is used. */
439class ConnectedOverlayPositionChange {
440 constructor(
441 /** The position used as a result of this change. */
442 connectionPair,
443 /** @docs-private */
444 scrollableViewProperties) {
445 this.connectionPair = connectionPair;
446 this.scrollableViewProperties = scrollableViewProperties;
447 }
448}
449ConnectedOverlayPositionChange.ctorParameters = () => [
450 { type: ConnectionPositionPair },
451 { type: ScrollingVisibility, decorators: [{ type: Optional }] }
452];
453/**
454 * Validates whether a vertical position property matches the expected values.
455 * @param property Name of the property being validated.
456 * @param value Value of the property being validated.
457 * @docs-private
458 */
459function validateVerticalPosition(property, value) {
460 if (value !== 'top' && value !== 'bottom' && value !== 'center') {
461 throw Error(`ConnectedPosition: Invalid ${property} "${value}". ` +
462 `Expected "top", "bottom" or "center".`);
463 }
464}
465/**
466 * Validates whether a horizontal position property matches the expected values.
467 * @param property Name of the property being validated.
468 * @param value Value of the property being validated.
469 * @docs-private
470 */
471function validateHorizontalPosition(property, value) {
472 if (value !== 'start' && value !== 'end' && value !== 'center') {
473 throw Error(`ConnectedPosition: Invalid ${property} "${value}". ` +
474 `Expected "start", "end" or "center".`);
475 }
476}
477
478/**
479 * @license
480 * Copyright Google LLC All Rights Reserved.
481 *
482 * Use of this source code is governed by an MIT-style license that can be
483 * found in the LICENSE file at https://angular.io/license
484 */
485/**
486 * Service for dispatching events that land on the body to appropriate overlay ref,
487 * if any. It maintains a list of attached overlays to determine best suited overlay based
488 * on event target and order of overlay opens.
489 */
490class BaseOverlayDispatcher {
491 constructor(document) {
492 /** Currently attached overlays in the order they were attached. */
493 this._attachedOverlays = [];
494 this._document = document;
495 }
496 ngOnDestroy() {
497 this.detach();
498 }
499 /** Add a new overlay to the list of attached overlay refs. */
500 add(overlayRef) {
501 // Ensure that we don't get the same overlay multiple times.
502 this.remove(overlayRef);
503 this._attachedOverlays.push(overlayRef);
504 }
505 /** Remove an overlay from the list of attached overlay refs. */
506 remove(overlayRef) {
507 const index = this._attachedOverlays.indexOf(overlayRef);
508 if (index > -1) {
509 this._attachedOverlays.splice(index, 1);
510 }
511 // Remove the global listener once there are no more overlays.
512 if (this._attachedOverlays.length === 0) {
513 this.detach();
514 }
515 }
516}
517BaseOverlayDispatcher.ɵprov = i0.ɵɵdefineInjectable({ factory: function BaseOverlayDispatcher_Factory() { return new BaseOverlayDispatcher(i0.ɵɵinject(i1$1.DOCUMENT)); }, token: BaseOverlayDispatcher, providedIn: "root" });
518BaseOverlayDispatcher.decorators = [
519 { type: Injectable, args: [{ providedIn: 'root' },] }
520];
521BaseOverlayDispatcher.ctorParameters = () => [
522 { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] }
523];
524
525/**
526 * @license
527 * Copyright Google LLC All Rights Reserved.
528 *
529 * Use of this source code is governed by an MIT-style license that can be
530 * found in the LICENSE file at https://angular.io/license
531 */
532/**
533 * Service for dispatching keyboard events that land on the body to appropriate overlay ref,
534 * if any. It maintains a list of attached overlays to determine best suited overlay based
535 * on event target and order of overlay opens.
536 */
537class OverlayKeyboardDispatcher extends BaseOverlayDispatcher {
538 constructor(document) {
539 super(document);
540 /** Keyboard event listener that will be attached to the body. */
541 this._keydownListener = (event) => {
542 const overlays = this._attachedOverlays;
543 for (let i = overlays.length - 1; i > -1; i--) {
544 // Dispatch the keydown event to the top overlay which has subscribers to its keydown events.
545 // We want to target the most recent overlay, rather than trying to match where the event came
546 // from, because some components might open an overlay, but keep focus on a trigger element
547 // (e.g. for select and autocomplete). We skip overlays without keydown event subscriptions,
548 // because we don't want overlays that don't handle keyboard events to block the ones below
549 // them that do.
550 if (overlays[i]._keydownEvents.observers.length > 0) {
551 overlays[i]._keydownEvents.next(event);
552 break;
553 }
554 }
555 };
556 }
557 /** Add a new overlay to the list of attached overlay refs. */
558 add(overlayRef) {
559 super.add(overlayRef);
560 // Lazily start dispatcher once first overlay is added
561 if (!this._isAttached) {
562 this._document.body.addEventListener('keydown', this._keydownListener);
563 this._isAttached = true;
564 }
565 }
566 /** Detaches the global keyboard event listener. */
567 detach() {
568 if (this._isAttached) {
569 this._document.body.removeEventListener('keydown', this._keydownListener);
570 this._isAttached = false;
571 }
572 }
573}
574OverlayKeyboardDispatcher.ɵprov = i0.ɵɵdefineInjectable({ factory: function OverlayKeyboardDispatcher_Factory() { return new OverlayKeyboardDispatcher(i0.ɵɵinject(i1$1.DOCUMENT)); }, token: OverlayKeyboardDispatcher, providedIn: "root" });
575OverlayKeyboardDispatcher.decorators = [
576 { type: Injectable, args: [{ providedIn: 'root' },] }
577];
578OverlayKeyboardDispatcher.ctorParameters = () => [
579 { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] }
580];
581
582/**
583 * @license
584 * Copyright Google LLC All Rights Reserved.
585 *
586 * Use of this source code is governed by an MIT-style license that can be
587 * found in the LICENSE file at https://angular.io/license
588 */
589/**
590 * Service for dispatching mouse click events that land on the body to appropriate overlay ref,
591 * if any. It maintains a list of attached overlays to determine best suited overlay based
592 * on event target and order of overlay opens.
593 */
594class OverlayOutsideClickDispatcher extends BaseOverlayDispatcher {
595 constructor(document, _platform) {
596 super(document);
597 this._platform = _platform;
598 this._cursorStyleIsSet = false;
599 /** Click event listener that will be attached to the body propagate phase. */
600 this._clickListener = (event) => {
601 const target = _getEventTarget(event);
602 // We copy the array because the original may be modified asynchronously if the
603 // outsidePointerEvents listener decides to detach overlays resulting in index errors inside
604 // the for loop.
605 const overlays = this._attachedOverlays.slice();
606 // Dispatch the mouse event to the top overlay which has subscribers to its mouse events.
607 // We want to target all overlays for which the click could be considered as outside click.
608 // As soon as we reach an overlay for which the click is not outside click we break off
609 // the loop.
610 for (let i = overlays.length - 1; i > -1; i--) {
611 const overlayRef = overlays[i];
612 if (overlayRef._outsidePointerEvents.observers.length < 1 || !overlayRef.hasAttached()) {
613 continue;
614 }
615 // If it's a click inside the overlay, just break - we should do nothing
616 // If it's an outside click dispatch the mouse event, and proceed with the next overlay
617 if (overlayRef.overlayElement.contains(target)) {
618 break;
619 }
620 overlayRef._outsidePointerEvents.next(event);
621 }
622 };
623 }
624 /** Add a new overlay to the list of attached overlay refs. */
625 add(overlayRef) {
626 super.add(overlayRef);
627 // Safari on iOS does not generate click events for non-interactive
628 // elements. However, we want to receive a click for any element outside
629 // the overlay. We can force a "clickable" state by setting
630 // `cursor: pointer` on the document body. See:
631 // https://developer.mozilla.org/en-US/docs/Web/API/Element/click_event#Safari_Mobile
632 // https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html
633 if (!this._isAttached) {
634 const body = this._document.body;
635 body.addEventListener('click', this._clickListener, true);
636 body.addEventListener('auxclick', this._clickListener, true);
637 body.addEventListener('contextmenu', this._clickListener, true);
638 // click event is not fired on iOS. To make element "clickable" we are
639 // setting the cursor to pointer
640 if (this._platform.IOS && !this._cursorStyleIsSet) {
641 this._cursorOriginalValue = body.style.cursor;
642 body.style.cursor = 'pointer';
643 this._cursorStyleIsSet = true;
644 }
645 this._isAttached = true;
646 }
647 }
648 /** Detaches the global keyboard event listener. */
649 detach() {
650 if (this._isAttached) {
651 const body = this._document.body;
652 body.removeEventListener('click', this._clickListener, true);
653 body.removeEventListener('auxclick', this._clickListener, true);
654 body.removeEventListener('contextmenu', this._clickListener, true);
655 if (this._platform.IOS && this._cursorStyleIsSet) {
656 body.style.cursor = this._cursorOriginalValue;
657 this._cursorStyleIsSet = false;
658 }
659 this._isAttached = false;
660 }
661 }
662}
663OverlayOutsideClickDispatcher.ɵprov = i0.ɵɵdefineInjectable({ factory: function OverlayOutsideClickDispatcher_Factory() { return new OverlayOutsideClickDispatcher(i0.ɵɵinject(i1$1.DOCUMENT), i0.ɵɵinject(i2.Platform)); }, token: OverlayOutsideClickDispatcher, providedIn: "root" });
664OverlayOutsideClickDispatcher.decorators = [
665 { type: Injectable, args: [{ providedIn: 'root' },] }
666];
667OverlayOutsideClickDispatcher.ctorParameters = () => [
668 { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
669 { type: Platform }
670];
671
672/**
673 * @license
674 * Copyright Google LLC All Rights Reserved.
675 *
676 * Use of this source code is governed by an MIT-style license that can be
677 * found in the LICENSE file at https://angular.io/license
678 */
679/** Container inside which all overlays will render. */
680class OverlayContainer {
681 constructor(document, _platform) {
682 this._platform = _platform;
683 this._document = document;
684 }
685 ngOnDestroy() {
686 const container = this._containerElement;
687 if (container && container.parentNode) {
688 container.parentNode.removeChild(container);
689 }
690 }
691 /**
692 * This method returns the overlay container element. It will lazily
693 * create the element the first time it is called to facilitate using
694 * the container in non-browser environments.
695 * @returns the container element
696 */
697 getContainerElement() {
698 if (!this._containerElement) {
699 this._createContainer();
700 }
701 return this._containerElement;
702 }
703 /**
704 * Create the overlay container element, which is simply a div
705 * with the 'cdk-overlay-container' class on the document body.
706 */
707 _createContainer() {
708 const containerClass = 'cdk-overlay-container';
709 // TODO(crisbeto): remove the testing check once we have an overlay testing
710 // module or Angular starts tearing down the testing `NgModule`. See:
711 // https://github.com/angular/angular/issues/18831
712 if (this._platform.isBrowser || _isTestEnvironment()) {
713 const oppositePlatformContainers = this._document.querySelectorAll(`.${containerClass}[platform="server"], ` +
714 `.${containerClass}[platform="test"]`);
715 // Remove any old containers from the opposite platform.
716 // This can happen when transitioning from the server to the client.
717 for (let i = 0; i < oppositePlatformContainers.length; i++) {
718 oppositePlatformContainers[i].parentNode.removeChild(oppositePlatformContainers[i]);
719 }
720 }
721 const container = this._document.createElement('div');
722 container.classList.add(containerClass);
723 // A long time ago we kept adding new overlay containers whenever a new app was instantiated,
724 // but at some point we added logic which clears the duplicate ones in order to avoid leaks.
725 // The new logic was a little too aggressive since it was breaking some legitimate use cases.
726 // To mitigate the problem we made it so that only containers from a different platform are
727 // cleared, but the side-effect was that people started depending on the overly-aggressive
728 // logic to clean up their tests for them. Until we can introduce an overlay-specific testing
729 // module which does the cleanup, we try to detect that we're in a test environment and we
730 // always clear the container. See #17006.
731 // TODO(crisbeto): remove the test environment check once we have an overlay testing module.
732 if (_isTestEnvironment()) {
733 container.setAttribute('platform', 'test');
734 }
735 else if (!this._platform.isBrowser) {
736 container.setAttribute('platform', 'server');
737 }
738 this._document.body.appendChild(container);
739 this._containerElement = container;
740 }
741}
742OverlayContainer.ɵprov = i0.ɵɵdefineInjectable({ factory: function OverlayContainer_Factory() { return new OverlayContainer(i0.ɵɵinject(i1$1.DOCUMENT), i0.ɵɵinject(i2.Platform)); }, token: OverlayContainer, providedIn: "root" });
743OverlayContainer.decorators = [
744 { type: Injectable, args: [{ providedIn: 'root' },] }
745];
746OverlayContainer.ctorParameters = () => [
747 { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
748 { type: Platform }
749];
750
751/**
752 * @license
753 * Copyright Google LLC All Rights Reserved.
754 *
755 * Use of this source code is governed by an MIT-style license that can be
756 * found in the LICENSE file at https://angular.io/license
757 */
758/**
759 * Reference to an overlay that has been created with the Overlay service.
760 * Used to manipulate or dispose of said overlay.
761 */
762class OverlayRef {
763 constructor(_portalOutlet, _host, _pane, _config, _ngZone, _keyboardDispatcher, _document, _location, _outsideClickDispatcher) {
764 this._portalOutlet = _portalOutlet;
765 this._host = _host;
766 this._pane = _pane;
767 this._config = _config;
768 this._ngZone = _ngZone;
769 this._keyboardDispatcher = _keyboardDispatcher;
770 this._document = _document;
771 this._location = _location;
772 this._outsideClickDispatcher = _outsideClickDispatcher;
773 this._backdropElement = null;
774 this._backdropClick = new Subject();
775 this._attachments = new Subject();
776 this._detachments = new Subject();
777 this._locationChanges = Subscription.EMPTY;
778 this._backdropClickHandler = (event) => this._backdropClick.next(event);
779 /** Stream of keydown events dispatched to this overlay. */
780 this._keydownEvents = new Subject();
781 /** Stream of mouse outside events dispatched to this overlay. */
782 this._outsidePointerEvents = new Subject();
783 if (_config.scrollStrategy) {
784 this._scrollStrategy = _config.scrollStrategy;
785 this._scrollStrategy.attach(this);
786 }
787 this._positionStrategy = _config.positionStrategy;
788 }
789 /** The overlay's HTML element */
790 get overlayElement() {
791 return this._pane;
792 }
793 /** The overlay's backdrop HTML element. */
794 get backdropElement() {
795 return this._backdropElement;
796 }
797 /**
798 * Wrapper around the panel element. Can be used for advanced
799 * positioning where a wrapper with specific styling is
800 * required around the overlay pane.
801 */
802 get hostElement() {
803 return this._host;
804 }
805 /**
806 * Attaches content, given via a Portal, to the overlay.
807 * If the overlay is configured to have a backdrop, it will be created.
808 *
809 * @param portal Portal instance to which to attach the overlay.
810 * @returns The portal attachment result.
811 */
812 attach(portal) {
813 let attachResult = this._portalOutlet.attach(portal);
814 // Update the pane element with the given configuration.
815 if (!this._host.parentElement && this._previousHostParent) {
816 this._previousHostParent.appendChild(this._host);
817 }
818 if (this._positionStrategy) {
819 this._positionStrategy.attach(this);
820 }
821 this._updateStackingOrder();
822 this._updateElementSize();
823 this._updateElementDirection();
824 if (this._scrollStrategy) {
825 this._scrollStrategy.enable();
826 }
827 // Update the position once the zone is stable so that the overlay will be fully rendered
828 // before attempting to position it, as the position may depend on the size of the rendered
829 // content.
830 this._ngZone.onStable
831 .pipe(take(1))
832 .subscribe(() => {
833 // The overlay could've been detached before the zone has stabilized.
834 if (this.hasAttached()) {
835 this.updatePosition();
836 }
837 });
838 // Enable pointer events for the overlay pane element.
839 this._togglePointerEvents(true);
840 if (this._config.hasBackdrop) {
841 this._attachBackdrop();
842 }
843 if (this._config.panelClass) {
844 this._toggleClasses(this._pane, this._config.panelClass, true);
845 }
846 // Only emit the `attachments` event once all other setup is done.
847 this._attachments.next();
848 // Track this overlay by the keyboard dispatcher
849 this._keyboardDispatcher.add(this);
850 if (this._config.disposeOnNavigation) {
851 this._locationChanges = this._location.subscribe(() => this.dispose());
852 }
853 this._outsideClickDispatcher.add(this);
854 return attachResult;
855 }
856 /**
857 * Detaches an overlay from a portal.
858 * @returns The portal detachment result.
859 */
860 detach() {
861 if (!this.hasAttached()) {
862 return;
863 }
864 this.detachBackdrop();
865 // When the overlay is detached, the pane element should disable pointer events.
866 // This is necessary because otherwise the pane element will cover the page and disable
867 // pointer events therefore. Depends on the position strategy and the applied pane boundaries.
868 this._togglePointerEvents(false);
869 if (this._positionStrategy && this._positionStrategy.detach) {
870 this._positionStrategy.detach();
871 }
872 if (this._scrollStrategy) {
873 this._scrollStrategy.disable();
874 }
875 const detachmentResult = this._portalOutlet.detach();
876 // Only emit after everything is detached.
877 this._detachments.next();
878 // Remove this overlay from keyboard dispatcher tracking.
879 this._keyboardDispatcher.remove(this);
880 // Keeping the host element in the DOM can cause scroll jank, because it still gets
881 // rendered, even though it's transparent and unclickable which is why we remove it.
882 this._detachContentWhenStable();
883 this._locationChanges.unsubscribe();
884 this._outsideClickDispatcher.remove(this);
885 return detachmentResult;
886 }
887 /** Cleans up the overlay from the DOM. */
888 dispose() {
889 const isAttached = this.hasAttached();
890 if (this._positionStrategy) {
891 this._positionStrategy.dispose();
892 }
893 this._disposeScrollStrategy();
894 this._disposeBackdrop(this._backdropElement);
895 this._locationChanges.unsubscribe();
896 this._keyboardDispatcher.remove(this);
897 this._portalOutlet.dispose();
898 this._attachments.complete();
899 this._backdropClick.complete();
900 this._keydownEvents.complete();
901 this._outsidePointerEvents.complete();
902 this._outsideClickDispatcher.remove(this);
903 if (this._host && this._host.parentNode) {
904 this._host.parentNode.removeChild(this._host);
905 this._host = null;
906 }
907 this._previousHostParent = this._pane = null;
908 if (isAttached) {
909 this._detachments.next();
910 }
911 this._detachments.complete();
912 }
913 /** Whether the overlay has attached content. */
914 hasAttached() {
915 return this._portalOutlet.hasAttached();
916 }
917 /** Gets an observable that emits when the backdrop has been clicked. */
918 backdropClick() {
919 return this._backdropClick;
920 }
921 /** Gets an observable that emits when the overlay has been attached. */
922 attachments() {
923 return this._attachments;
924 }
925 /** Gets an observable that emits when the overlay has been detached. */
926 detachments() {
927 return this._detachments;
928 }
929 /** Gets an observable of keydown events targeted to this overlay. */
930 keydownEvents() {
931 return this._keydownEvents;
932 }
933 /** Gets an observable of pointer events targeted outside this overlay. */
934 outsidePointerEvents() {
935 return this._outsidePointerEvents;
936 }
937 /** Gets the current overlay configuration, which is immutable. */
938 getConfig() {
939 return this._config;
940 }
941 /** Updates the position of the overlay based on the position strategy. */
942 updatePosition() {
943 if (this._positionStrategy) {
944 this._positionStrategy.apply();
945 }
946 }
947 /** Switches to a new position strategy and updates the overlay position. */
948 updatePositionStrategy(strategy) {
949 if (strategy === this._positionStrategy) {
950 return;
951 }
952 if (this._positionStrategy) {
953 this._positionStrategy.dispose();
954 }
955 this._positionStrategy = strategy;
956 if (this.hasAttached()) {
957 strategy.attach(this);
958 this.updatePosition();
959 }
960 }
961 /** Update the size properties of the overlay. */
962 updateSize(sizeConfig) {
963 this._config = Object.assign(Object.assign({}, this._config), sizeConfig);
964 this._updateElementSize();
965 }
966 /** Sets the LTR/RTL direction for the overlay. */
967 setDirection(dir) {
968 this._config = Object.assign(Object.assign({}, this._config), { direction: dir });
969 this._updateElementDirection();
970 }
971 /** Add a CSS class or an array of classes to the overlay pane. */
972 addPanelClass(classes) {
973 if (this._pane) {
974 this._toggleClasses(this._pane, classes, true);
975 }
976 }
977 /** Remove a CSS class or an array of classes from the overlay pane. */
978 removePanelClass(classes) {
979 if (this._pane) {
980 this._toggleClasses(this._pane, classes, false);
981 }
982 }
983 /**
984 * Returns the layout direction of the overlay panel.
985 */
986 getDirection() {
987 const direction = this._config.direction;
988 if (!direction) {
989 return 'ltr';
990 }
991 return typeof direction === 'string' ? direction : direction.value;
992 }
993 /** Switches to a new scroll strategy. */
994 updateScrollStrategy(strategy) {
995 if (strategy === this._scrollStrategy) {
996 return;
997 }
998 this._disposeScrollStrategy();
999 this._scrollStrategy = strategy;
1000 if (this.hasAttached()) {
1001 strategy.attach(this);
1002 strategy.enable();
1003 }
1004 }
1005 /** Updates the text direction of the overlay panel. */
1006 _updateElementDirection() {
1007 this._host.setAttribute('dir', this.getDirection());
1008 }
1009 /** Updates the size of the overlay element based on the overlay config. */
1010 _updateElementSize() {
1011 if (!this._pane) {
1012 return;
1013 }
1014 const style = this._pane.style;
1015 style.width = coerceCssPixelValue(this._config.width);
1016 style.height = coerceCssPixelValue(this._config.height);
1017 style.minWidth = coerceCssPixelValue(this._config.minWidth);
1018 style.minHeight = coerceCssPixelValue(this._config.minHeight);
1019 style.maxWidth = coerceCssPixelValue(this._config.maxWidth);
1020 style.maxHeight = coerceCssPixelValue(this._config.maxHeight);
1021 }
1022 /** Toggles the pointer events for the overlay pane element. */
1023 _togglePointerEvents(enablePointer) {
1024 this._pane.style.pointerEvents = enablePointer ? '' : 'none';
1025 }
1026 /** Attaches a backdrop for this overlay. */
1027 _attachBackdrop() {
1028 const showingClass = 'cdk-overlay-backdrop-showing';
1029 this._backdropElement = this._document.createElement('div');
1030 this._backdropElement.classList.add('cdk-overlay-backdrop');
1031 if (this._config.backdropClass) {
1032 this._toggleClasses(this._backdropElement, this._config.backdropClass, true);
1033 }
1034 // Insert the backdrop before the pane in the DOM order,
1035 // in order to handle stacked overlays properly.
1036 this._host.parentElement.insertBefore(this._backdropElement, this._host);
1037 // Forward backdrop clicks such that the consumer of the overlay can perform whatever
1038 // action desired when such a click occurs (usually closing the overlay).
1039 this._backdropElement.addEventListener('click', this._backdropClickHandler);
1040 // Add class to fade-in the backdrop after one frame.
1041 if (typeof requestAnimationFrame !== 'undefined') {
1042 this._ngZone.runOutsideAngular(() => {
1043 requestAnimationFrame(() => {
1044 if (this._backdropElement) {
1045 this._backdropElement.classList.add(showingClass);
1046 }
1047 });
1048 });
1049 }
1050 else {
1051 this._backdropElement.classList.add(showingClass);
1052 }
1053 }
1054 /**
1055 * Updates the stacking order of the element, moving it to the top if necessary.
1056 * This is required in cases where one overlay was detached, while another one,
1057 * that should be behind it, was destroyed. The next time both of them are opened,
1058 * the stacking will be wrong, because the detached element's pane will still be
1059 * in its original DOM position.
1060 */
1061 _updateStackingOrder() {
1062 if (this._host.nextSibling) {
1063 this._host.parentNode.appendChild(this._host);
1064 }
1065 }
1066 /** Detaches the backdrop (if any) associated with the overlay. */
1067 detachBackdrop() {
1068 const backdropToDetach = this._backdropElement;
1069 if (!backdropToDetach) {
1070 return;
1071 }
1072 let timeoutId;
1073 const finishDetach = () => {
1074 // It may not be attached to anything in certain cases (e.g. unit tests).
1075 if (backdropToDetach) {
1076 backdropToDetach.removeEventListener('click', this._backdropClickHandler);
1077 backdropToDetach.removeEventListener('transitionend', finishDetach);
1078 this._disposeBackdrop(backdropToDetach);
1079 }
1080 if (this._config.backdropClass) {
1081 this._toggleClasses(backdropToDetach, this._config.backdropClass, false);
1082 }
1083 clearTimeout(timeoutId);
1084 };
1085 backdropToDetach.classList.remove('cdk-overlay-backdrop-showing');
1086 this._ngZone.runOutsideAngular(() => {
1087 backdropToDetach.addEventListener('transitionend', finishDetach);
1088 });
1089 // If the backdrop doesn't have a transition, the `transitionend` event won't fire.
1090 // In this case we make it unclickable and we try to remove it after a delay.
1091 backdropToDetach.style.pointerEvents = 'none';
1092 // Run this outside the Angular zone because there's nothing that Angular cares about.
1093 // If it were to run inside the Angular zone, every test that used Overlay would have to be
1094 // either async or fakeAsync.
1095 timeoutId = this._ngZone.runOutsideAngular(() => setTimeout(finishDetach, 500));
1096 }
1097 /** Toggles a single CSS class or an array of classes on an element. */
1098 _toggleClasses(element, cssClasses, isAdd) {
1099 const classList = element.classList;
1100 coerceArray(cssClasses).forEach(cssClass => {
1101 // We can't do a spread here, because IE doesn't support setting multiple classes.
1102 // Also trying to add an empty string to a DOMTokenList will throw.
1103 if (cssClass) {
1104 isAdd ? classList.add(cssClass) : classList.remove(cssClass);
1105 }
1106 });
1107 }
1108 /** Detaches the overlay content next time the zone stabilizes. */
1109 _detachContentWhenStable() {
1110 // Normally we wouldn't have to explicitly run this outside the `NgZone`, however
1111 // if the consumer is using `zone-patch-rxjs`, the `Subscription.unsubscribe` call will
1112 // be patched to run inside the zone, which will throw us into an infinite loop.
1113 this._ngZone.runOutsideAngular(() => {
1114 // We can't remove the host here immediately, because the overlay pane's content
1115 // might still be animating. This stream helps us avoid interrupting the animation
1116 // by waiting for the pane to become empty.
1117 const subscription = this._ngZone.onStable
1118 .pipe(takeUntil(merge(this._attachments, this._detachments)))
1119 .subscribe(() => {
1120 // Needs a couple of checks for the pane and host, because
1121 // they may have been removed by the time the zone stabilizes.
1122 if (!this._pane || !this._host || this._pane.children.length === 0) {
1123 if (this._pane && this._config.panelClass) {
1124 this._toggleClasses(this._pane, this._config.panelClass, false);
1125 }
1126 if (this._host && this._host.parentElement) {
1127 this._previousHostParent = this._host.parentElement;
1128 this._previousHostParent.removeChild(this._host);
1129 }
1130 subscription.unsubscribe();
1131 }
1132 });
1133 });
1134 }
1135 /** Disposes of a scroll strategy. */
1136 _disposeScrollStrategy() {
1137 const scrollStrategy = this._scrollStrategy;
1138 if (scrollStrategy) {
1139 scrollStrategy.disable();
1140 if (scrollStrategy.detach) {
1141 scrollStrategy.detach();
1142 }
1143 }
1144 }
1145 /** Removes a backdrop element from the DOM. */
1146 _disposeBackdrop(backdrop) {
1147 if (backdrop) {
1148 if (backdrop.parentNode) {
1149 backdrop.parentNode.removeChild(backdrop);
1150 }
1151 // It is possible that a new portal has been attached to this overlay since we started
1152 // removing the backdrop. If that is the case, only clear the backdrop reference if it
1153 // is still the same instance that we started to remove.
1154 if (this._backdropElement === backdrop) {
1155 this._backdropElement = null;
1156 }
1157 }
1158 }
1159}
1160
1161/**
1162 * @license
1163 * Copyright Google LLC All Rights Reserved.
1164 *
1165 * Use of this source code is governed by an MIT-style license that can be
1166 * found in the LICENSE file at https://angular.io/license
1167 */
1168// TODO: refactor clipping detection into a separate thing (part of scrolling module)
1169// TODO: doesn't handle both flexible width and height when it has to scroll along both axis.
1170/** Class to be added to the overlay bounding box. */
1171const boundingBoxClass = 'cdk-overlay-connected-position-bounding-box';
1172/** Regex used to split a string on its CSS units. */
1173const cssUnitPattern = /([A-Za-z%]+)$/;
1174/**
1175 * A strategy for positioning overlays. Using this strategy, an overlay is given an
1176 * implicit position relative some origin element. The relative position is defined in terms of
1177 * a point on the origin element that is connected to a point on the overlay element. For example,
1178 * a basic dropdown is connecting the bottom-left corner of the origin to the top-left corner
1179 * of the overlay.
1180 */
1181class FlexibleConnectedPositionStrategy {
1182 constructor(connectedTo, _viewportRuler, _document, _platform, _overlayContainer) {
1183 this._viewportRuler = _viewportRuler;
1184 this._document = _document;
1185 this._platform = _platform;
1186 this._overlayContainer = _overlayContainer;
1187 /** Last size used for the bounding box. Used to avoid resizing the overlay after open. */
1188 this._lastBoundingBoxSize = { width: 0, height: 0 };
1189 /** Whether the overlay was pushed in a previous positioning. */
1190 this._isPushed = false;
1191 /** Whether the overlay can be pushed on-screen on the initial open. */
1192 this._canPush = true;
1193 /** Whether the overlay can grow via flexible width/height after the initial open. */
1194 this._growAfterOpen = false;
1195 /** Whether the overlay's width and height can be constrained to fit within the viewport. */
1196 this._hasFlexibleDimensions = true;
1197 /** Whether the overlay position is locked. */
1198 this._positionLocked = false;
1199 /** Amount of space that must be maintained between the overlay and the edge of the viewport. */
1200 this._viewportMargin = 0;
1201 /** The Scrollable containers used to check scrollable view properties on position change. */
1202 this._scrollables = [];
1203 /** Ordered list of preferred positions, from most to least desirable. */
1204 this._preferredPositions = [];
1205 /** Subject that emits whenever the position changes. */
1206 this._positionChanges = new Subject();
1207 /** Subscription to viewport size changes. */
1208 this._resizeSubscription = Subscription.EMPTY;
1209 /** Default offset for the overlay along the x axis. */
1210 this._offsetX = 0;
1211 /** Default offset for the overlay along the y axis. */
1212 this._offsetY = 0;
1213 /** Keeps track of the CSS classes that the position strategy has applied on the overlay panel. */
1214 this._appliedPanelClasses = [];
1215 /** Observable sequence of position changes. */
1216 this.positionChanges = this._positionChanges;
1217 this.setOrigin(connectedTo);
1218 }
1219 /** Ordered list of preferred positions, from most to least desirable. */
1220 get positions() {
1221 return this._preferredPositions;
1222 }
1223 /** Attaches this position strategy to an overlay. */
1224 attach(overlayRef) {
1225 if (this._overlayRef && overlayRef !== this._overlayRef &&
1226 (typeof ngDevMode === 'undefined' || ngDevMode)) {
1227 throw Error('This position strategy is already attached to an overlay');
1228 }
1229 this._validatePositions();
1230 overlayRef.hostElement.classList.add(boundingBoxClass);
1231 this._overlayRef = overlayRef;
1232 this._boundingBox = overlayRef.hostElement;
1233 this._pane = overlayRef.overlayElement;
1234 this._isDisposed = false;
1235 this._isInitialRender = true;
1236 this._lastPosition = null;
1237 this._resizeSubscription.unsubscribe();
1238 this._resizeSubscription = this._viewportRuler.change().subscribe(() => {
1239 // When the window is resized, we want to trigger the next reposition as if it
1240 // was an initial render, in order for the strategy to pick a new optimal position,
1241 // otherwise position locking will cause it to stay at the old one.
1242 this._isInitialRender = true;
1243 this.apply();
1244 });
1245 }
1246 /**
1247 * Updates the position of the overlay element, using whichever preferred position relative
1248 * to the origin best fits on-screen.
1249 *
1250 * The selection of a position goes as follows:
1251 * - If any positions fit completely within the viewport as-is,
1252 * choose the first position that does so.
1253 * - If flexible dimensions are enabled and at least one satifies the given minimum width/height,
1254 * choose the position with the greatest available size modified by the positions' weight.
1255 * - If pushing is enabled, take the position that went off-screen the least and push it
1256 * on-screen.
1257 * - If none of the previous criteria were met, use the position that goes off-screen the least.
1258 * @docs-private
1259 */
1260 apply() {
1261 // We shouldn't do anything if the strategy was disposed or we're on the server.
1262 if (this._isDisposed || !this._platform.isBrowser) {
1263 return;
1264 }
1265 // If the position has been applied already (e.g. when the overlay was opened) and the
1266 // consumer opted into locking in the position, re-use the old position, in order to
1267 // prevent the overlay from jumping around.
1268 if (!this._isInitialRender && this._positionLocked && this._lastPosition) {
1269 this.reapplyLastPosition();
1270 return;
1271 }
1272 this._clearPanelClasses();
1273 this._resetOverlayElementStyles();
1274 this._resetBoundingBoxStyles();
1275 // We need the bounding rects for the origin and the overlay to determine how to position
1276 // the overlay relative to the origin.
1277 // We use the viewport rect to determine whether a position would go off-screen.
1278 this._viewportRect = this._getNarrowedViewportRect();
1279 this._originRect = this._getOriginRect();
1280 this._overlayRect = this._pane.getBoundingClientRect();
1281 const originRect = this._originRect;
1282 const overlayRect = this._overlayRect;
1283 const viewportRect = this._viewportRect;
1284 // Positions where the overlay will fit with flexible dimensions.
1285 const flexibleFits = [];
1286 // Fallback if none of the preferred positions fit within the viewport.
1287 let fallback;
1288 // Go through each of the preferred positions looking for a good fit.
1289 // If a good fit is found, it will be applied immediately.
1290 for (let pos of this._preferredPositions) {
1291 // Get the exact (x, y) coordinate for the point-of-origin on the origin element.
1292 let originPoint = this._getOriginPoint(originRect, pos);
1293 // From that point-of-origin, get the exact (x, y) coordinate for the top-left corner of the
1294 // overlay in this position. We use the top-left corner for calculations and later translate
1295 // this into an appropriate (top, left, bottom, right) style.
1296 let overlayPoint = this._getOverlayPoint(originPoint, overlayRect, pos);
1297 // Calculate how well the overlay would fit into the viewport with this point.
1298 let overlayFit = this._getOverlayFit(overlayPoint, overlayRect, viewportRect, pos);
1299 // If the overlay, without any further work, fits into the viewport, use this position.
1300 if (overlayFit.isCompletelyWithinViewport) {
1301 this._isPushed = false;
1302 this._applyPosition(pos, originPoint);
1303 return;
1304 }
1305 // If the overlay has flexible dimensions, we can use this position
1306 // so long as there's enough space for the minimum dimensions.
1307 if (this._canFitWithFlexibleDimensions(overlayFit, overlayPoint, viewportRect)) {
1308 // Save positions where the overlay will fit with flexible dimensions. We will use these
1309 // if none of the positions fit *without* flexible dimensions.
1310 flexibleFits.push({
1311 position: pos,
1312 origin: originPoint,
1313 overlayRect,
1314 boundingBoxRect: this._calculateBoundingBoxRect(originPoint, pos)
1315 });
1316 continue;
1317 }
1318 // If the current preferred position does not fit on the screen, remember the position
1319 // if it has more visible area on-screen than we've seen and move onto the next preferred
1320 // position.
1321 if (!fallback || fallback.overlayFit.visibleArea < overlayFit.visibleArea) {
1322 fallback = { overlayFit, overlayPoint, originPoint, position: pos, overlayRect };
1323 }
1324 }
1325 // If there are any positions where the overlay would fit with flexible dimensions, choose the
1326 // one that has the greatest area available modified by the position's weight
1327 if (flexibleFits.length) {
1328 let bestFit = null;
1329 let bestScore = -1;
1330 for (const fit of flexibleFits) {
1331 const score = fit.boundingBoxRect.width * fit.boundingBoxRect.height * (fit.position.weight || 1);
1332 if (score > bestScore) {
1333 bestScore = score;
1334 bestFit = fit;
1335 }
1336 }
1337 this._isPushed = false;
1338 this._applyPosition(bestFit.position, bestFit.origin);
1339 return;
1340 }
1341 // When none of the preferred positions fit within the viewport, take the position
1342 // that went off-screen the least and attempt to push it on-screen.
1343 if (this._canPush) {
1344 // TODO(jelbourn): after pushing, the opening "direction" of the overlay might not make sense.
1345 this._isPushed = true;
1346 this._applyPosition(fallback.position, fallback.originPoint);
1347 return;
1348 }
1349 // All options for getting the overlay within the viewport have been exhausted, so go with the
1350 // position that went off-screen the least.
1351 this._applyPosition(fallback.position, fallback.originPoint);
1352 }
1353 detach() {
1354 this._clearPanelClasses();
1355 this._lastPosition = null;
1356 this._previousPushAmount = null;
1357 this._resizeSubscription.unsubscribe();
1358 }
1359 /** Cleanup after the element gets destroyed. */
1360 dispose() {
1361 if (this._isDisposed) {
1362 return;
1363 }
1364 // We can't use `_resetBoundingBoxStyles` here, because it resets
1365 // some properties to zero, rather than removing them.
1366 if (this._boundingBox) {
1367 extendStyles(this._boundingBox.style, {
1368 top: '',
1369 left: '',
1370 right: '',
1371 bottom: '',
1372 height: '',
1373 width: '',
1374 alignItems: '',
1375 justifyContent: '',
1376 });
1377 }
1378 if (this._pane) {
1379 this._resetOverlayElementStyles();
1380 }
1381 if (this._overlayRef) {
1382 this._overlayRef.hostElement.classList.remove(boundingBoxClass);
1383 }
1384 this.detach();
1385 this._positionChanges.complete();
1386 this._overlayRef = this._boundingBox = null;
1387 this._isDisposed = true;
1388 }
1389 /**
1390 * This re-aligns the overlay element with the trigger in its last calculated position,
1391 * even if a position higher in the "preferred positions" list would now fit. This
1392 * allows one to re-align the panel without changing the orientation of the panel.
1393 */
1394 reapplyLastPosition() {
1395 if (!this._isDisposed && (!this._platform || this._platform.isBrowser)) {
1396 this._originRect = this._getOriginRect();
1397 this._overlayRect = this._pane.getBoundingClientRect();
1398 this._viewportRect = this._getNarrowedViewportRect();
1399 const lastPosition = this._lastPosition || this._preferredPositions[0];
1400 const originPoint = this._getOriginPoint(this._originRect, lastPosition);
1401 this._applyPosition(lastPosition, originPoint);
1402 }
1403 }
1404 /**
1405 * Sets the list of Scrollable containers that host the origin element so that
1406 * on reposition we can evaluate if it or the overlay has been clipped or outside view. Every
1407 * Scrollable must be an ancestor element of the strategy's origin element.
1408 */
1409 withScrollableContainers(scrollables) {
1410 this._scrollables = scrollables;
1411 return this;
1412 }
1413 /**
1414 * Adds new preferred positions.
1415 * @param positions List of positions options for this overlay.
1416 */
1417 withPositions(positions) {
1418 this._preferredPositions = positions;
1419 // If the last calculated position object isn't part of the positions anymore, clear
1420 // it in order to avoid it being picked up if the consumer tries to re-apply.
1421 if (positions.indexOf(this._lastPosition) === -1) {
1422 this._lastPosition = null;
1423 }
1424 this._validatePositions();
1425 return this;
1426 }
1427 /**
1428 * Sets a minimum distance the overlay may be positioned to the edge of the viewport.
1429 * @param margin Required margin between the overlay and the viewport edge in pixels.
1430 */
1431 withViewportMargin(margin) {
1432 this._viewportMargin = margin;
1433 return this;
1434 }
1435 /** Sets whether the overlay's width and height can be constrained to fit within the viewport. */
1436 withFlexibleDimensions(flexibleDimensions = true) {
1437 this._hasFlexibleDimensions = flexibleDimensions;
1438 return this;
1439 }
1440 /** Sets whether the overlay can grow after the initial open via flexible width/height. */
1441 withGrowAfterOpen(growAfterOpen = true) {
1442 this._growAfterOpen = growAfterOpen;
1443 return this;
1444 }
1445 /** Sets whether the overlay can be pushed on-screen if none of the provided positions fit. */
1446 withPush(canPush = true) {
1447 this._canPush = canPush;
1448 return this;
1449 }
1450 /**
1451 * Sets whether the overlay's position should be locked in after it is positioned
1452 * initially. When an overlay is locked in, it won't attempt to reposition itself
1453 * when the position is re-applied (e.g. when the user scrolls away).
1454 * @param isLocked Whether the overlay should locked in.
1455 */
1456 withLockedPosition(isLocked = true) {
1457 this._positionLocked = isLocked;
1458 return this;
1459 }
1460 /**
1461 * Sets the origin, relative to which to position the overlay.
1462 * Using an element origin is useful for building components that need to be positioned
1463 * relatively to a trigger (e.g. dropdown menus or tooltips), whereas using a point can be
1464 * used for cases like contextual menus which open relative to the user's pointer.
1465 * @param origin Reference to the new origin.
1466 */
1467 setOrigin(origin) {
1468 this._origin = origin;
1469 return this;
1470 }
1471 /**
1472 * Sets the default offset for the overlay's connection point on the x-axis.
1473 * @param offset New offset in the X axis.
1474 */
1475 withDefaultOffsetX(offset) {
1476 this._offsetX = offset;
1477 return this;
1478 }
1479 /**
1480 * Sets the default offset for the overlay's connection point on the y-axis.
1481 * @param offset New offset in the Y axis.
1482 */
1483 withDefaultOffsetY(offset) {
1484 this._offsetY = offset;
1485 return this;
1486 }
1487 /**
1488 * Configures that the position strategy should set a `transform-origin` on some elements
1489 * inside the overlay, depending on the current position that is being applied. This is
1490 * useful for the cases where the origin of an animation can change depending on the
1491 * alignment of the overlay.
1492 * @param selector CSS selector that will be used to find the target
1493 * elements onto which to set the transform origin.
1494 */
1495 withTransformOriginOn(selector) {
1496 this._transformOriginSelector = selector;
1497 return this;
1498 }
1499 /**
1500 * Gets the (x, y) coordinate of a connection point on the origin based on a relative position.
1501 */
1502 _getOriginPoint(originRect, pos) {
1503 let x;
1504 if (pos.originX == 'center') {
1505 // Note: when centering we should always use the `left`
1506 // offset, otherwise the position will be wrong in RTL.
1507 x = originRect.left + (originRect.width / 2);
1508 }
1509 else {
1510 const startX = this._isRtl() ? originRect.right : originRect.left;
1511 const endX = this._isRtl() ? originRect.left : originRect.right;
1512 x = pos.originX == 'start' ? startX : endX;
1513 }
1514 let y;
1515 if (pos.originY == 'center') {
1516 y = originRect.top + (originRect.height / 2);
1517 }
1518 else {
1519 y = pos.originY == 'top' ? originRect.top : originRect.bottom;
1520 }
1521 return { x, y };
1522 }
1523 /**
1524 * Gets the (x, y) coordinate of the top-left corner of the overlay given a given position and
1525 * origin point to which the overlay should be connected.
1526 */
1527 _getOverlayPoint(originPoint, overlayRect, pos) {
1528 // Calculate the (overlayStartX, overlayStartY), the start of the
1529 // potential overlay position relative to the origin point.
1530 let overlayStartX;
1531 if (pos.overlayX == 'center') {
1532 overlayStartX = -overlayRect.width / 2;
1533 }
1534 else if (pos.overlayX === 'start') {
1535 overlayStartX = this._isRtl() ? -overlayRect.width : 0;
1536 }
1537 else {
1538 overlayStartX = this._isRtl() ? 0 : -overlayRect.width;
1539 }
1540 let overlayStartY;
1541 if (pos.overlayY == 'center') {
1542 overlayStartY = -overlayRect.height / 2;
1543 }
1544 else {
1545 overlayStartY = pos.overlayY == 'top' ? 0 : -overlayRect.height;
1546 }
1547 // The (x, y) coordinates of the overlay.
1548 return {
1549 x: originPoint.x + overlayStartX,
1550 y: originPoint.y + overlayStartY,
1551 };
1552 }
1553 /** Gets how well an overlay at the given point will fit within the viewport. */
1554 _getOverlayFit(point, rawOverlayRect, viewport, position) {
1555 // Round the overlay rect when comparing against the
1556 // viewport, because the viewport is always rounded.
1557 const overlay = getRoundedBoundingClientRect(rawOverlayRect);
1558 let { x, y } = point;
1559 let offsetX = this._getOffset(position, 'x');
1560 let offsetY = this._getOffset(position, 'y');
1561 // Account for the offsets since they could push the overlay out of the viewport.
1562 if (offsetX) {
1563 x += offsetX;
1564 }
1565 if (offsetY) {
1566 y += offsetY;
1567 }
1568 // How much the overlay would overflow at this position, on each side.
1569 let leftOverflow = 0 - x;
1570 let rightOverflow = (x + overlay.width) - viewport.width;
1571 let topOverflow = 0 - y;
1572 let bottomOverflow = (y + overlay.height) - viewport.height;
1573 // Visible parts of the element on each axis.
1574 let visibleWidth = this._subtractOverflows(overlay.width, leftOverflow, rightOverflow);
1575 let visibleHeight = this._subtractOverflows(overlay.height, topOverflow, bottomOverflow);
1576 let visibleArea = visibleWidth * visibleHeight;
1577 return {
1578 visibleArea,
1579 isCompletelyWithinViewport: (overlay.width * overlay.height) === visibleArea,
1580 fitsInViewportVertically: visibleHeight === overlay.height,
1581 fitsInViewportHorizontally: visibleWidth == overlay.width,
1582 };
1583 }
1584 /**
1585 * Whether the overlay can fit within the viewport when it may resize either its width or height.
1586 * @param fit How well the overlay fits in the viewport at some position.
1587 * @param point The (x, y) coordinates of the overlat at some position.
1588 * @param viewport The geometry of the viewport.
1589 */
1590 _canFitWithFlexibleDimensions(fit, point, viewport) {
1591 if (this._hasFlexibleDimensions) {
1592 const availableHeight = viewport.bottom - point.y;
1593 const availableWidth = viewport.right - point.x;
1594 const minHeight = getPixelValue(this._overlayRef.getConfig().minHeight);
1595 const minWidth = getPixelValue(this._overlayRef.getConfig().minWidth);
1596 const verticalFit = fit.fitsInViewportVertically ||
1597 (minHeight != null && minHeight <= availableHeight);
1598 const horizontalFit = fit.fitsInViewportHorizontally ||
1599 (minWidth != null && minWidth <= availableWidth);
1600 return verticalFit && horizontalFit;
1601 }
1602 return false;
1603 }
1604 /**
1605 * Gets the point at which the overlay can be "pushed" on-screen. If the overlay is larger than
1606 * the viewport, the top-left corner will be pushed on-screen (with overflow occuring on the
1607 * right and bottom).
1608 *
1609 * @param start Starting point from which the overlay is pushed.
1610 * @param overlay Dimensions of the overlay.
1611 * @param scrollPosition Current viewport scroll position.
1612 * @returns The point at which to position the overlay after pushing. This is effectively a new
1613 * originPoint.
1614 */
1615 _pushOverlayOnScreen(start, rawOverlayRect, scrollPosition) {
1616 // If the position is locked and we've pushed the overlay already, reuse the previous push
1617 // amount, rather than pushing it again. If we were to continue pushing, the element would
1618 // remain in the viewport, which goes against the expectations when position locking is enabled.
1619 if (this._previousPushAmount && this._positionLocked) {
1620 return {
1621 x: start.x + this._previousPushAmount.x,
1622 y: start.y + this._previousPushAmount.y
1623 };
1624 }
1625 // Round the overlay rect when comparing against the
1626 // viewport, because the viewport is always rounded.
1627 const overlay = getRoundedBoundingClientRect(rawOverlayRect);
1628 const viewport = this._viewportRect;
1629 // Determine how much the overlay goes outside the viewport on each
1630 // side, which we'll use to decide which direction to push it.
1631 const overflowRight = Math.max(start.x + overlay.width - viewport.width, 0);
1632 const overflowBottom = Math.max(start.y + overlay.height - viewport.height, 0);
1633 const overflowTop = Math.max(viewport.top - scrollPosition.top - start.y, 0);
1634 const overflowLeft = Math.max(viewport.left - scrollPosition.left - start.x, 0);
1635 // Amount by which to push the overlay in each axis such that it remains on-screen.
1636 let pushX = 0;
1637 let pushY = 0;
1638 // If the overlay fits completely within the bounds of the viewport, push it from whichever
1639 // direction is goes off-screen. Otherwise, push the top-left corner such that its in the
1640 // viewport and allow for the trailing end of the overlay to go out of bounds.
1641 if (overlay.width <= viewport.width) {
1642 pushX = overflowLeft || -overflowRight;
1643 }
1644 else {
1645 pushX = start.x < this._viewportMargin ? (viewport.left - scrollPosition.left) - start.x : 0;
1646 }
1647 if (overlay.height <= viewport.height) {
1648 pushY = overflowTop || -overflowBottom;
1649 }
1650 else {
1651 pushY = start.y < this._viewportMargin ? (viewport.top - scrollPosition.top) - start.y : 0;
1652 }
1653 this._previousPushAmount = { x: pushX, y: pushY };
1654 return {
1655 x: start.x + pushX,
1656 y: start.y + pushY,
1657 };
1658 }
1659 /**
1660 * Applies a computed position to the overlay and emits a position change.
1661 * @param position The position preference
1662 * @param originPoint The point on the origin element where the overlay is connected.
1663 */
1664 _applyPosition(position, originPoint) {
1665 this._setTransformOrigin(position);
1666 this._setOverlayElementStyles(originPoint, position);
1667 this._setBoundingBoxStyles(originPoint, position);
1668 if (position.panelClass) {
1669 this._addPanelClasses(position.panelClass);
1670 }
1671 // Save the last connected position in case the position needs to be re-calculated.
1672 this._lastPosition = position;
1673 // Notify that the position has been changed along with its change properties.
1674 // We only emit if we've got any subscriptions, because the scroll visibility
1675 // calculcations can be somewhat expensive.
1676 if (this._positionChanges.observers.length) {
1677 const scrollableViewProperties = this._getScrollVisibility();
1678 const changeEvent = new ConnectedOverlayPositionChange(position, scrollableViewProperties);
1679 this._positionChanges.next(changeEvent);
1680 }
1681 this._isInitialRender = false;
1682 }
1683 /** Sets the transform origin based on the configured selector and the passed-in position. */
1684 _setTransformOrigin(position) {
1685 if (!this._transformOriginSelector) {
1686 return;
1687 }
1688 const elements = this._boundingBox.querySelectorAll(this._transformOriginSelector);
1689 let xOrigin;
1690 let yOrigin = position.overlayY;
1691 if (position.overlayX === 'center') {
1692 xOrigin = 'center';
1693 }
1694 else if (this._isRtl()) {
1695 xOrigin = position.overlayX === 'start' ? 'right' : 'left';
1696 }
1697 else {
1698 xOrigin = position.overlayX === 'start' ? 'left' : 'right';
1699 }
1700 for (let i = 0; i < elements.length; i++) {
1701 elements[i].style.transformOrigin = `${xOrigin} ${yOrigin}`;
1702 }
1703 }
1704 /**
1705 * Gets the position and size of the overlay's sizing container.
1706 *
1707 * This method does no measuring and applies no styles so that we can cheaply compute the
1708 * bounds for all positions and choose the best fit based on these results.
1709 */
1710 _calculateBoundingBoxRect(origin, position) {
1711 const viewport = this._viewportRect;
1712 const isRtl = this._isRtl();
1713 let height, top, bottom;
1714 if (position.overlayY === 'top') {
1715 // Overlay is opening "downward" and thus is bound by the bottom viewport edge.
1716 top = origin.y;
1717 height = viewport.height - top + this._viewportMargin;
1718 }
1719 else if (position.overlayY === 'bottom') {
1720 // Overlay is opening "upward" and thus is bound by the top viewport edge. We need to add
1721 // the viewport margin back in, because the viewport rect is narrowed down to remove the
1722 // margin, whereas the `origin` position is calculated based on its `ClientRect`.
1723 bottom = viewport.height - origin.y + this._viewportMargin * 2;
1724 height = viewport.height - bottom + this._viewportMargin;
1725 }
1726 else {
1727 // If neither top nor bottom, it means that the overlay is vertically centered on the
1728 // origin point. Note that we want the position relative to the viewport, rather than
1729 // the page, which is why we don't use something like `viewport.bottom - origin.y` and
1730 // `origin.y - viewport.top`.
1731 const smallestDistanceToViewportEdge = Math.min(viewport.bottom - origin.y + viewport.top, origin.y);
1732 const previousHeight = this._lastBoundingBoxSize.height;
1733 height = smallestDistanceToViewportEdge * 2;
1734 top = origin.y - smallestDistanceToViewportEdge;
1735 if (height > previousHeight && !this._isInitialRender && !this._growAfterOpen) {
1736 top = origin.y - (previousHeight / 2);
1737 }
1738 }
1739 // The overlay is opening 'right-ward' (the content flows to the right).
1740 const isBoundedByRightViewportEdge = (position.overlayX === 'start' && !isRtl) ||
1741 (position.overlayX === 'end' && isRtl);
1742 // The overlay is opening 'left-ward' (the content flows to the left).
1743 const isBoundedByLeftViewportEdge = (position.overlayX === 'end' && !isRtl) ||
1744 (position.overlayX === 'start' && isRtl);
1745 let width, left, right;
1746 if (isBoundedByLeftViewportEdge) {
1747 right = viewport.width - origin.x + this._viewportMargin;
1748 width = origin.x - this._viewportMargin;
1749 }
1750 else if (isBoundedByRightViewportEdge) {
1751 left = origin.x;
1752 width = viewport.right - origin.x;
1753 }
1754 else {
1755 // If neither start nor end, it means that the overlay is horizontally centered on the
1756 // origin point. Note that we want the position relative to the viewport, rather than
1757 // the page, which is why we don't use something like `viewport.right - origin.x` and
1758 // `origin.x - viewport.left`.
1759 const smallestDistanceToViewportEdge = Math.min(viewport.right - origin.x + viewport.left, origin.x);
1760 const previousWidth = this._lastBoundingBoxSize.width;
1761 width = smallestDistanceToViewportEdge * 2;
1762 left = origin.x - smallestDistanceToViewportEdge;
1763 if (width > previousWidth && !this._isInitialRender && !this._growAfterOpen) {
1764 left = origin.x - (previousWidth / 2);
1765 }
1766 }
1767 return { top: top, left: left, bottom: bottom, right: right, width, height };
1768 }
1769 /**
1770 * Sets the position and size of the overlay's sizing wrapper. The wrapper is positioned on the
1771 * origin's connection point and stetches to the bounds of the viewport.
1772 *
1773 * @param origin The point on the origin element where the overlay is connected.
1774 * @param position The position preference
1775 */
1776 _setBoundingBoxStyles(origin, position) {
1777 const boundingBoxRect = this._calculateBoundingBoxRect(origin, position);
1778 // It's weird if the overlay *grows* while scrolling, so we take the last size into account
1779 // when applying a new size.
1780 if (!this._isInitialRender && !this._growAfterOpen) {
1781 boundingBoxRect.height = Math.min(boundingBoxRect.height, this._lastBoundingBoxSize.height);
1782 boundingBoxRect.width = Math.min(boundingBoxRect.width, this._lastBoundingBoxSize.width);
1783 }
1784 const styles = {};
1785 if (this._hasExactPosition()) {
1786 styles.top = styles.left = '0';
1787 styles.bottom = styles.right = styles.maxHeight = styles.maxWidth = '';
1788 styles.width = styles.height = '100%';
1789 }
1790 else {
1791 const maxHeight = this._overlayRef.getConfig().maxHeight;
1792 const maxWidth = this._overlayRef.getConfig().maxWidth;
1793 styles.height = coerceCssPixelValue(boundingBoxRect.height);
1794 styles.top = coerceCssPixelValue(boundingBoxRect.top);
1795 styles.bottom = coerceCssPixelValue(boundingBoxRect.bottom);
1796 styles.width = coerceCssPixelValue(boundingBoxRect.width);
1797 styles.left = coerceCssPixelValue(boundingBoxRect.left);
1798 styles.right = coerceCssPixelValue(boundingBoxRect.right);
1799 // Push the pane content towards the proper direction.
1800 if (position.overlayX === 'center') {
1801 styles.alignItems = 'center';
1802 }
1803 else {
1804 styles.alignItems = position.overlayX === 'end' ? 'flex-end' : 'flex-start';
1805 }
1806 if (position.overlayY === 'center') {
1807 styles.justifyContent = 'center';
1808 }
1809 else {
1810 styles.justifyContent = position.overlayY === 'bottom' ? 'flex-end' : 'flex-start';
1811 }
1812 if (maxHeight) {
1813 styles.maxHeight = coerceCssPixelValue(maxHeight);
1814 }
1815 if (maxWidth) {
1816 styles.maxWidth = coerceCssPixelValue(maxWidth);
1817 }
1818 }
1819 this._lastBoundingBoxSize = boundingBoxRect;
1820 extendStyles(this._boundingBox.style, styles);
1821 }
1822 /** Resets the styles for the bounding box so that a new positioning can be computed. */
1823 _resetBoundingBoxStyles() {
1824 extendStyles(this._boundingBox.style, {
1825 top: '0',
1826 left: '0',
1827 right: '0',
1828 bottom: '0',
1829 height: '',
1830 width: '',
1831 alignItems: '',
1832 justifyContent: '',
1833 });
1834 }
1835 /** Resets the styles for the overlay pane so that a new positioning can be computed. */
1836 _resetOverlayElementStyles() {
1837 extendStyles(this._pane.style, {
1838 top: '',
1839 left: '',
1840 bottom: '',
1841 right: '',
1842 position: '',
1843 transform: '',
1844 });
1845 }
1846 /** Sets positioning styles to the overlay element. */
1847 _setOverlayElementStyles(originPoint, position) {
1848 const styles = {};
1849 const hasExactPosition = this._hasExactPosition();
1850 const hasFlexibleDimensions = this._hasFlexibleDimensions;
1851 const config = this._overlayRef.getConfig();
1852 if (hasExactPosition) {
1853 const scrollPosition = this._viewportRuler.getViewportScrollPosition();
1854 extendStyles(styles, this._getExactOverlayY(position, originPoint, scrollPosition));
1855 extendStyles(styles, this._getExactOverlayX(position, originPoint, scrollPosition));
1856 }
1857 else {
1858 styles.position = 'static';
1859 }
1860 // Use a transform to apply the offsets. We do this because the `center` positions rely on
1861 // being in the normal flex flow and setting a `top` / `left` at all will completely throw
1862 // off the position. We also can't use margins, because they won't have an effect in some
1863 // cases where the element doesn't have anything to "push off of". Finally, this works
1864 // better both with flexible and non-flexible positioning.
1865 let transformString = '';
1866 let offsetX = this._getOffset(position, 'x');
1867 let offsetY = this._getOffset(position, 'y');
1868 if (offsetX) {
1869 transformString += `translateX(${offsetX}px) `;
1870 }
1871 if (offsetY) {
1872 transformString += `translateY(${offsetY}px)`;
1873 }
1874 styles.transform = transformString.trim();
1875 // If a maxWidth or maxHeight is specified on the overlay, we remove them. We do this because
1876 // we need these values to both be set to "100%" for the automatic flexible sizing to work.
1877 // The maxHeight and maxWidth are set on the boundingBox in order to enforce the constraint.
1878 // Note that this doesn't apply when we have an exact position, in which case we do want to
1879 // apply them because they'll be cleared from the bounding box.
1880 if (config.maxHeight) {
1881 if (hasExactPosition) {
1882 styles.maxHeight = coerceCssPixelValue(config.maxHeight);
1883 }
1884 else if (hasFlexibleDimensions) {
1885 styles.maxHeight = '';
1886 }
1887 }
1888 if (config.maxWidth) {
1889 if (hasExactPosition) {
1890 styles.maxWidth = coerceCssPixelValue(config.maxWidth);
1891 }
1892 else if (hasFlexibleDimensions) {
1893 styles.maxWidth = '';
1894 }
1895 }
1896 extendStyles(this._pane.style, styles);
1897 }
1898 /** Gets the exact top/bottom for the overlay when not using flexible sizing or when pushing. */
1899 _getExactOverlayY(position, originPoint, scrollPosition) {
1900 // Reset any existing styles. This is necessary in case the
1901 // preferred position has changed since the last `apply`.
1902 let styles = { top: '', bottom: '' };
1903 let overlayPoint = this._getOverlayPoint(originPoint, this._overlayRect, position);
1904 if (this._isPushed) {
1905 overlayPoint = this._pushOverlayOnScreen(overlayPoint, this._overlayRect, scrollPosition);
1906 }
1907 let virtualKeyboardOffset = this._overlayContainer.getContainerElement().getBoundingClientRect().top;
1908 // Normally this would be zero, however when the overlay is attached to an input (e.g. in an
1909 // autocomplete), mobile browsers will shift everything in order to put the input in the middle
1910 // of the screen and to make space for the virtual keyboard. We need to account for this offset,
1911 // otherwise our positioning will be thrown off.
1912 overlayPoint.y -= virtualKeyboardOffset;
1913 // We want to set either `top` or `bottom` based on whether the overlay wants to appear
1914 // above or below the origin and the direction in which the element will expand.
1915 if (position.overlayY === 'bottom') {
1916 // When using `bottom`, we adjust the y position such that it is the distance
1917 // from the bottom of the viewport rather than the top.
1918 const documentHeight = this._document.documentElement.clientHeight;
1919 styles.bottom = `${documentHeight - (overlayPoint.y + this._overlayRect.height)}px`;
1920 }
1921 else {
1922 styles.top = coerceCssPixelValue(overlayPoint.y);
1923 }
1924 return styles;
1925 }
1926 /** Gets the exact left/right for the overlay when not using flexible sizing or when pushing. */
1927 _getExactOverlayX(position, originPoint, scrollPosition) {
1928 // Reset any existing styles. This is necessary in case the preferred position has
1929 // changed since the last `apply`.
1930 let styles = { left: '', right: '' };
1931 let overlayPoint = this._getOverlayPoint(originPoint, this._overlayRect, position);
1932 if (this._isPushed) {
1933 overlayPoint = this._pushOverlayOnScreen(overlayPoint, this._overlayRect, scrollPosition);
1934 }
1935 // We want to set either `left` or `right` based on whether the overlay wants to appear "before"
1936 // or "after" the origin, which determines the direction in which the element will expand.
1937 // For the horizontal axis, the meaning of "before" and "after" change based on whether the
1938 // page is in RTL or LTR.
1939 let horizontalStyleProperty;
1940 if (this._isRtl()) {
1941 horizontalStyleProperty = position.overlayX === 'end' ? 'left' : 'right';
1942 }
1943 else {
1944 horizontalStyleProperty = position.overlayX === 'end' ? 'right' : 'left';
1945 }
1946 // When we're setting `right`, we adjust the x position such that it is the distance
1947 // from the right edge of the viewport rather than the left edge.
1948 if (horizontalStyleProperty === 'right') {
1949 const documentWidth = this._document.documentElement.clientWidth;
1950 styles.right = `${documentWidth - (overlayPoint.x + this._overlayRect.width)}px`;
1951 }
1952 else {
1953 styles.left = coerceCssPixelValue(overlayPoint.x);
1954 }
1955 return styles;
1956 }
1957 /**
1958 * Gets the view properties of the trigger and overlay, including whether they are clipped
1959 * or completely outside the view of any of the strategy's scrollables.
1960 */
1961 _getScrollVisibility() {
1962 // Note: needs fresh rects since the position could've changed.
1963 const originBounds = this._getOriginRect();
1964 const overlayBounds = this._pane.getBoundingClientRect();
1965 // TODO(jelbourn): instead of needing all of the client rects for these scrolling containers
1966 // every time, we should be able to use the scrollTop of the containers if the size of those
1967 // containers hasn't changed.
1968 const scrollContainerBounds = this._scrollables.map(scrollable => {
1969 return scrollable.getElementRef().nativeElement.getBoundingClientRect();
1970 });
1971 return {
1972 isOriginClipped: isElementClippedByScrolling(originBounds, scrollContainerBounds),
1973 isOriginOutsideView: isElementScrolledOutsideView(originBounds, scrollContainerBounds),
1974 isOverlayClipped: isElementClippedByScrolling(overlayBounds, scrollContainerBounds),
1975 isOverlayOutsideView: isElementScrolledOutsideView(overlayBounds, scrollContainerBounds),
1976 };
1977 }
1978 /** Subtracts the amount that an element is overflowing on an axis from its length. */
1979 _subtractOverflows(length, ...overflows) {
1980 return overflows.reduce((currentValue, currentOverflow) => {
1981 return currentValue - Math.max(currentOverflow, 0);
1982 }, length);
1983 }
1984 /** Narrows the given viewport rect by the current _viewportMargin. */
1985 _getNarrowedViewportRect() {
1986 // We recalculate the viewport rect here ourselves, rather than using the ViewportRuler,
1987 // because we want to use the `clientWidth` and `clientHeight` as the base. The difference
1988 // being that the client properties don't include the scrollbar, as opposed to `innerWidth`
1989 // and `innerHeight` that do. This is necessary, because the overlay container uses
1990 // 100% `width` and `height` which don't include the scrollbar either.
1991 const width = this._document.documentElement.clientWidth;
1992 const height = this._document.documentElement.clientHeight;
1993 const scrollPosition = this._viewportRuler.getViewportScrollPosition();
1994 return {
1995 top: scrollPosition.top + this._viewportMargin,
1996 left: scrollPosition.left + this._viewportMargin,
1997 right: scrollPosition.left + width - this._viewportMargin,
1998 bottom: scrollPosition.top + height - this._viewportMargin,
1999 width: width - (2 * this._viewportMargin),
2000 height: height - (2 * this._viewportMargin),
2001 };
2002 }
2003 /** Whether the we're dealing with an RTL context */
2004 _isRtl() {
2005 return this._overlayRef.getDirection() === 'rtl';
2006 }
2007 /** Determines whether the overlay uses exact or flexible positioning. */
2008 _hasExactPosition() {
2009 return !this._hasFlexibleDimensions || this._isPushed;
2010 }
2011 /** Retrieves the offset of a position along the x or y axis. */
2012 _getOffset(position, axis) {
2013 if (axis === 'x') {
2014 // We don't do something like `position['offset' + axis]` in
2015 // order to avoid breking minifiers that rename properties.
2016 return position.offsetX == null ? this._offsetX : position.offsetX;
2017 }
2018 return position.offsetY == null ? this._offsetY : position.offsetY;
2019 }
2020 /** Validates that the current position match the expected values. */
2021 _validatePositions() {
2022 if (typeof ngDevMode === 'undefined' || ngDevMode) {
2023 if (!this._preferredPositions.length) {
2024 throw Error('FlexibleConnectedPositionStrategy: At least one position is required.');
2025 }
2026 // TODO(crisbeto): remove these once Angular's template type
2027 // checking is advanced enough to catch these cases.
2028 this._preferredPositions.forEach(pair => {
2029 validateHorizontalPosition('originX', pair.originX);
2030 validateVerticalPosition('originY', pair.originY);
2031 validateHorizontalPosition('overlayX', pair.overlayX);
2032 validateVerticalPosition('overlayY', pair.overlayY);
2033 });
2034 }
2035 }
2036 /** Adds a single CSS class or an array of classes on the overlay panel. */
2037 _addPanelClasses(cssClasses) {
2038 if (this._pane) {
2039 coerceArray(cssClasses).forEach(cssClass => {
2040 if (cssClass !== '' && this._appliedPanelClasses.indexOf(cssClass) === -1) {
2041 this._appliedPanelClasses.push(cssClass);
2042 this._pane.classList.add(cssClass);
2043 }
2044 });
2045 }
2046 }
2047 /** Clears the classes that the position strategy has applied from the overlay panel. */
2048 _clearPanelClasses() {
2049 if (this._pane) {
2050 this._appliedPanelClasses.forEach(cssClass => {
2051 this._pane.classList.remove(cssClass);
2052 });
2053 this._appliedPanelClasses = [];
2054 }
2055 }
2056 /** Returns the ClientRect of the current origin. */
2057 _getOriginRect() {
2058 const origin = this._origin;
2059 if (origin instanceof ElementRef) {
2060 return origin.nativeElement.getBoundingClientRect();
2061 }
2062 // Check for Element so SVG elements are also supported.
2063 if (origin instanceof Element) {
2064 return origin.getBoundingClientRect();
2065 }
2066 const width = origin.width || 0;
2067 const height = origin.height || 0;
2068 // If the origin is a point, return a client rect as if it was a 0x0 element at the point.
2069 return {
2070 top: origin.y,
2071 bottom: origin.y + height,
2072 left: origin.x,
2073 right: origin.x + width,
2074 height,
2075 width
2076 };
2077 }
2078}
2079/** Shallow-extends a stylesheet object with another stylesheet object. */
2080function extendStyles(destination, source) {
2081 for (let key in source) {
2082 if (source.hasOwnProperty(key)) {
2083 destination[key] = source[key];
2084 }
2085 }
2086 return destination;
2087}
2088/**
2089 * Extracts the pixel value as a number from a value, if it's a number
2090 * or a CSS pixel string (e.g. `1337px`). Otherwise returns null.
2091 */
2092function getPixelValue(input) {
2093 if (typeof input !== 'number' && input != null) {
2094 const [value, units] = input.split(cssUnitPattern);
2095 return (!units || units === 'px') ? parseFloat(value) : null;
2096 }
2097 return input || null;
2098}
2099/**
2100 * Gets a version of an element's bounding `ClientRect` where all the values are rounded down to
2101 * the nearest pixel. This allows us to account for the cases where there may be sub-pixel
2102 * deviations in the `ClientRect` returned by the browser (e.g. when zoomed in with a percentage
2103 * size, see #21350).
2104 */
2105function getRoundedBoundingClientRect(clientRect) {
2106 return {
2107 top: Math.floor(clientRect.top),
2108 right: Math.floor(clientRect.right),
2109 bottom: Math.floor(clientRect.bottom),
2110 left: Math.floor(clientRect.left),
2111 width: Math.floor(clientRect.width),
2112 height: Math.floor(clientRect.height)
2113 };
2114}
2115
2116/**
2117 * @license
2118 * Copyright Google LLC All Rights Reserved.
2119 *
2120 * Use of this source code is governed by an MIT-style license that can be
2121 * found in the LICENSE file at https://angular.io/license
2122 */
2123/**
2124 * A strategy for positioning overlays. Using this strategy, an overlay is given an
2125 * implicit position relative to some origin element. The relative position is defined in terms of
2126 * a point on the origin element that is connected to a point on the overlay element. For example,
2127 * a basic dropdown is connecting the bottom-left corner of the origin to the top-left corner
2128 * of the overlay.
2129 * @deprecated Use `FlexibleConnectedPositionStrategy` instead.
2130 * @breaking-change 8.0.0
2131 */
2132class ConnectedPositionStrategy {
2133 constructor(originPos, overlayPos, connectedTo, viewportRuler, document, platform, overlayContainer) {
2134 /** Ordered list of preferred positions, from most to least desirable. */
2135 this._preferredPositions = [];
2136 // Since the `ConnectedPositionStrategy` is deprecated and we don't want to maintain
2137 // the extra logic, we create an instance of the positioning strategy that has some
2138 // defaults that make it behave as the old position strategy and to which we'll
2139 // proxy all of the API calls.
2140 this._positionStrategy = new FlexibleConnectedPositionStrategy(connectedTo, viewportRuler, document, platform, overlayContainer)
2141 .withFlexibleDimensions(false)
2142 .withPush(false)
2143 .withViewportMargin(0);
2144 this.withFallbackPosition(originPos, overlayPos);
2145 this.onPositionChange = this._positionStrategy.positionChanges;
2146 }
2147 /** Ordered list of preferred positions, from most to least desirable. */
2148 get positions() {
2149 return this._preferredPositions;
2150 }
2151 /** Attach this position strategy to an overlay. */
2152 attach(overlayRef) {
2153 this._overlayRef = overlayRef;
2154 this._positionStrategy.attach(overlayRef);
2155 if (this._direction) {
2156 overlayRef.setDirection(this._direction);
2157 this._direction = null;
2158 }
2159 }
2160 /** Disposes all resources used by the position strategy. */
2161 dispose() {
2162 this._positionStrategy.dispose();
2163 }
2164 /** @docs-private */
2165 detach() {
2166 this._positionStrategy.detach();
2167 }
2168 /**
2169 * Updates the position of the overlay element, using whichever preferred position relative
2170 * to the origin fits on-screen.
2171 * @docs-private
2172 */
2173 apply() {
2174 this._positionStrategy.apply();
2175 }
2176 /**
2177 * Re-positions the overlay element with the trigger in its last calculated position,
2178 * even if a position higher in the "preferred positions" list would now fit. This
2179 * allows one to re-align the panel without changing the orientation of the panel.
2180 */
2181 recalculateLastPosition() {
2182 this._positionStrategy.reapplyLastPosition();
2183 }
2184 /**
2185 * Sets the list of Scrollable containers that host the origin element so that
2186 * on reposition we can evaluate if it or the overlay has been clipped or outside view. Every
2187 * Scrollable must be an ancestor element of the strategy's origin element.
2188 */
2189 withScrollableContainers(scrollables) {
2190 this._positionStrategy.withScrollableContainers(scrollables);
2191 }
2192 /**
2193 * Adds a new preferred fallback position.
2194 * @param originPos
2195 * @param overlayPos
2196 */
2197 withFallbackPosition(originPos, overlayPos, offsetX, offsetY) {
2198 const position = new ConnectionPositionPair(originPos, overlayPos, offsetX, offsetY);
2199 this._preferredPositions.push(position);
2200 this._positionStrategy.withPositions(this._preferredPositions);
2201 return this;
2202 }
2203 /**
2204 * Sets the layout direction so the overlay's position can be adjusted to match.
2205 * @param dir New layout direction.
2206 */
2207 withDirection(dir) {
2208 // Since the direction might be declared before the strategy is attached,
2209 // we save the value in a temporary property and we'll transfer it to the
2210 // overlay ref on attachment.
2211 if (this._overlayRef) {
2212 this._overlayRef.setDirection(dir);
2213 }
2214 else {
2215 this._direction = dir;
2216 }
2217 return this;
2218 }
2219 /**
2220 * Sets an offset for the overlay's connection point on the x-axis
2221 * @param offset New offset in the X axis.
2222 */
2223 withOffsetX(offset) {
2224 this._positionStrategy.withDefaultOffsetX(offset);
2225 return this;
2226 }
2227 /**
2228 * Sets an offset for the overlay's connection point on the y-axis
2229 * @param offset New offset in the Y axis.
2230 */
2231 withOffsetY(offset) {
2232 this._positionStrategy.withDefaultOffsetY(offset);
2233 return this;
2234 }
2235 /**
2236 * Sets whether the overlay's position should be locked in after it is positioned
2237 * initially. When an overlay is locked in, it won't attempt to reposition itself
2238 * when the position is re-applied (e.g. when the user scrolls away).
2239 * @param isLocked Whether the overlay should locked in.
2240 */
2241 withLockedPosition(isLocked) {
2242 this._positionStrategy.withLockedPosition(isLocked);
2243 return this;
2244 }
2245 /**
2246 * Overwrites the current set of positions with an array of new ones.
2247 * @param positions Position pairs to be set on the strategy.
2248 */
2249 withPositions(positions) {
2250 this._preferredPositions = positions.slice();
2251 this._positionStrategy.withPositions(this._preferredPositions);
2252 return this;
2253 }
2254 /**
2255 * Sets the origin element, relative to which to position the overlay.
2256 * @param origin Reference to the new origin element.
2257 */
2258 setOrigin(origin) {
2259 this._positionStrategy.setOrigin(origin);
2260 return this;
2261 }
2262}
2263
2264/**
2265 * @license
2266 * Copyright Google LLC All Rights Reserved.
2267 *
2268 * Use of this source code is governed by an MIT-style license that can be
2269 * found in the LICENSE file at https://angular.io/license
2270 */
2271/** Class to be added to the overlay pane wrapper. */
2272const wrapperClass = 'cdk-global-overlay-wrapper';
2273/**
2274 * A strategy for positioning overlays. Using this strategy, an overlay is given an
2275 * explicit position relative to the browser's viewport. We use flexbox, instead of
2276 * transforms, in order to avoid issues with subpixel rendering which can cause the
2277 * element to become blurry.
2278 */
2279class GlobalPositionStrategy {
2280 constructor() {
2281 this._cssPosition = 'static';
2282 this._topOffset = '';
2283 this._bottomOffset = '';
2284 this._leftOffset = '';
2285 this._rightOffset = '';
2286 this._alignItems = '';
2287 this._justifyContent = '';
2288 this._width = '';
2289 this._height = '';
2290 }
2291 attach(overlayRef) {
2292 const config = overlayRef.getConfig();
2293 this._overlayRef = overlayRef;
2294 if (this._width && !config.width) {
2295 overlayRef.updateSize({ width: this._width });
2296 }
2297 if (this._height && !config.height) {
2298 overlayRef.updateSize({ height: this._height });
2299 }
2300 overlayRef.hostElement.classList.add(wrapperClass);
2301 this._isDisposed = false;
2302 }
2303 /**
2304 * Sets the top position of the overlay. Clears any previously set vertical position.
2305 * @param value New top offset.
2306 */
2307 top(value = '') {
2308 this._bottomOffset = '';
2309 this._topOffset = value;
2310 this._alignItems = 'flex-start';
2311 return this;
2312 }
2313 /**
2314 * Sets the left position of the overlay. Clears any previously set horizontal position.
2315 * @param value New left offset.
2316 */
2317 left(value = '') {
2318 this._rightOffset = '';
2319 this._leftOffset = value;
2320 this._justifyContent = 'flex-start';
2321 return this;
2322 }
2323 /**
2324 * Sets the bottom position of the overlay. Clears any previously set vertical position.
2325 * @param value New bottom offset.
2326 */
2327 bottom(value = '') {
2328 this._topOffset = '';
2329 this._bottomOffset = value;
2330 this._alignItems = 'flex-end';
2331 return this;
2332 }
2333 /**
2334 * Sets the right position of the overlay. Clears any previously set horizontal position.
2335 * @param value New right offset.
2336 */
2337 right(value = '') {
2338 this._leftOffset = '';
2339 this._rightOffset = value;
2340 this._justifyContent = 'flex-end';
2341 return this;
2342 }
2343 /**
2344 * Sets the overlay width and clears any previously set width.
2345 * @param value New width for the overlay
2346 * @deprecated Pass the `width` through the `OverlayConfig`.
2347 * @breaking-change 8.0.0
2348 */
2349 width(value = '') {
2350 if (this._overlayRef) {
2351 this._overlayRef.updateSize({ width: value });
2352 }
2353 else {
2354 this._width = value;
2355 }
2356 return this;
2357 }
2358 /**
2359 * Sets the overlay height and clears any previously set height.
2360 * @param value New height for the overlay
2361 * @deprecated Pass the `height` through the `OverlayConfig`.
2362 * @breaking-change 8.0.0
2363 */
2364 height(value = '') {
2365 if (this._overlayRef) {
2366 this._overlayRef.updateSize({ height: value });
2367 }
2368 else {
2369 this._height = value;
2370 }
2371 return this;
2372 }
2373 /**
2374 * Centers the overlay horizontally with an optional offset.
2375 * Clears any previously set horizontal position.
2376 *
2377 * @param offset Overlay offset from the horizontal center.
2378 */
2379 centerHorizontally(offset = '') {
2380 this.left(offset);
2381 this._justifyContent = 'center';
2382 return this;
2383 }
2384 /**
2385 * Centers the overlay vertically with an optional offset.
2386 * Clears any previously set vertical position.
2387 *
2388 * @param offset Overlay offset from the vertical center.
2389 */
2390 centerVertically(offset = '') {
2391 this.top(offset);
2392 this._alignItems = 'center';
2393 return this;
2394 }
2395 /**
2396 * Apply the position to the element.
2397 * @docs-private
2398 */
2399 apply() {
2400 // Since the overlay ref applies the strategy asynchronously, it could
2401 // have been disposed before it ends up being applied. If that is the
2402 // case, we shouldn't do anything.
2403 if (!this._overlayRef || !this._overlayRef.hasAttached()) {
2404 return;
2405 }
2406 const styles = this._overlayRef.overlayElement.style;
2407 const parentStyles = this._overlayRef.hostElement.style;
2408 const config = this._overlayRef.getConfig();
2409 const { width, height, maxWidth, maxHeight } = config;
2410 const shouldBeFlushHorizontally = (width === '100%' || width === '100vw') &&
2411 (!maxWidth || maxWidth === '100%' || maxWidth === '100vw');
2412 const shouldBeFlushVertically = (height === '100%' || height === '100vh') &&
2413 (!maxHeight || maxHeight === '100%' || maxHeight === '100vh');
2414 styles.position = this._cssPosition;
2415 styles.marginLeft = shouldBeFlushHorizontally ? '0' : this._leftOffset;
2416 styles.marginTop = shouldBeFlushVertically ? '0' : this._topOffset;
2417 styles.marginBottom = this._bottomOffset;
2418 styles.marginRight = this._rightOffset;
2419 if (shouldBeFlushHorizontally) {
2420 parentStyles.justifyContent = 'flex-start';
2421 }
2422 else if (this._justifyContent === 'center') {
2423 parentStyles.justifyContent = 'center';
2424 }
2425 else if (this._overlayRef.getConfig().direction === 'rtl') {
2426 // In RTL the browser will invert `flex-start` and `flex-end` automatically, but we
2427 // don't want that because our positioning is explicitly `left` and `right`, hence
2428 // why we do another inversion to ensure that the overlay stays in the same position.
2429 // TODO: reconsider this if we add `start` and `end` methods.
2430 if (this._justifyContent === 'flex-start') {
2431 parentStyles.justifyContent = 'flex-end';
2432 }
2433 else if (this._justifyContent === 'flex-end') {
2434 parentStyles.justifyContent = 'flex-start';
2435 }
2436 }
2437 else {
2438 parentStyles.justifyContent = this._justifyContent;
2439 }
2440 parentStyles.alignItems = shouldBeFlushVertically ? 'flex-start' : this._alignItems;
2441 }
2442 /**
2443 * Cleans up the DOM changes from the position strategy.
2444 * @docs-private
2445 */
2446 dispose() {
2447 if (this._isDisposed || !this._overlayRef) {
2448 return;
2449 }
2450 const styles = this._overlayRef.overlayElement.style;
2451 const parent = this._overlayRef.hostElement;
2452 const parentStyles = parent.style;
2453 parent.classList.remove(wrapperClass);
2454 parentStyles.justifyContent = parentStyles.alignItems = styles.marginTop =
2455 styles.marginBottom = styles.marginLeft = styles.marginRight = styles.position = '';
2456 this._overlayRef = null;
2457 this._isDisposed = true;
2458 }
2459}
2460
2461/**
2462 * @license
2463 * Copyright Google LLC All Rights Reserved.
2464 *
2465 * Use of this source code is governed by an MIT-style license that can be
2466 * found in the LICENSE file at https://angular.io/license
2467 */
2468/** Builder for overlay position strategy. */
2469class OverlayPositionBuilder {
2470 constructor(_viewportRuler, _document, _platform, _overlayContainer) {
2471 this._viewportRuler = _viewportRuler;
2472 this._document = _document;
2473 this._platform = _platform;
2474 this._overlayContainer = _overlayContainer;
2475 }
2476 /**
2477 * Creates a global position strategy.
2478 */
2479 global() {
2480 return new GlobalPositionStrategy();
2481 }
2482 /**
2483 * Creates a relative position strategy.
2484 * @param elementRef
2485 * @param originPos
2486 * @param overlayPos
2487 * @deprecated Use `flexibleConnectedTo` instead.
2488 * @breaking-change 8.0.0
2489 */
2490 connectedTo(elementRef, originPos, overlayPos) {
2491 return new ConnectedPositionStrategy(originPos, overlayPos, elementRef, this._viewportRuler, this._document, this._platform, this._overlayContainer);
2492 }
2493 /**
2494 * Creates a flexible position strategy.
2495 * @param origin Origin relative to which to position the overlay.
2496 */
2497 flexibleConnectedTo(origin) {
2498 return new FlexibleConnectedPositionStrategy(origin, this._viewportRuler, this._document, this._platform, this._overlayContainer);
2499 }
2500}
2501OverlayPositionBuilder.ɵprov = i0.ɵɵdefineInjectable({ factory: function OverlayPositionBuilder_Factory() { return new OverlayPositionBuilder(i0.ɵɵinject(i1.ViewportRuler), i0.ɵɵinject(i1$1.DOCUMENT), i0.ɵɵinject(i2.Platform), i0.ɵɵinject(OverlayContainer)); }, token: OverlayPositionBuilder, providedIn: "root" });
2502OverlayPositionBuilder.decorators = [
2503 { type: Injectable, args: [{ providedIn: 'root' },] }
2504];
2505OverlayPositionBuilder.ctorParameters = () => [
2506 { type: ViewportRuler },
2507 { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
2508 { type: Platform },
2509 { type: OverlayContainer }
2510];
2511
2512/**
2513 * @license
2514 * Copyright Google LLC All Rights Reserved.
2515 *
2516 * Use of this source code is governed by an MIT-style license that can be
2517 * found in the LICENSE file at https://angular.io/license
2518 */
2519/** Next overlay unique ID. */
2520let nextUniqueId = 0;
2521// Note that Overlay is *not* scoped to the app root because of the ComponentFactoryResolver
2522// which needs to be different depending on where OverlayModule is imported.
2523/**
2524 * Service to create Overlays. Overlays are dynamically added pieces of floating UI, meant to be
2525 * used as a low-level building block for other components. Dialogs, tooltips, menus,
2526 * selects, etc. can all be built using overlays. The service should primarily be used by authors
2527 * of re-usable components rather than developers building end-user applications.
2528 *
2529 * An overlay *is* a PortalOutlet, so any kind of Portal can be loaded into one.
2530 */
2531class Overlay {
2532 constructor(
2533 /** Scrolling strategies that can be used when creating an overlay. */
2534 scrollStrategies, _overlayContainer, _componentFactoryResolver, _positionBuilder, _keyboardDispatcher, _injector, _ngZone, _document, _directionality, _location, _outsideClickDispatcher) {
2535 this.scrollStrategies = scrollStrategies;
2536 this._overlayContainer = _overlayContainer;
2537 this._componentFactoryResolver = _componentFactoryResolver;
2538 this._positionBuilder = _positionBuilder;
2539 this._keyboardDispatcher = _keyboardDispatcher;
2540 this._injector = _injector;
2541 this._ngZone = _ngZone;
2542 this._document = _document;
2543 this._directionality = _directionality;
2544 this._location = _location;
2545 this._outsideClickDispatcher = _outsideClickDispatcher;
2546 }
2547 /**
2548 * Creates an overlay.
2549 * @param config Configuration applied to the overlay.
2550 * @returns Reference to the created overlay.
2551 */
2552 create(config) {
2553 const host = this._createHostElement();
2554 const pane = this._createPaneElement(host);
2555 const portalOutlet = this._createPortalOutlet(pane);
2556 const overlayConfig = new OverlayConfig(config);
2557 overlayConfig.direction = overlayConfig.direction || this._directionality.value;
2558 return new OverlayRef(portalOutlet, host, pane, overlayConfig, this._ngZone, this._keyboardDispatcher, this._document, this._location, this._outsideClickDispatcher);
2559 }
2560 /**
2561 * Gets a position builder that can be used, via fluent API,
2562 * to construct and configure a position strategy.
2563 * @returns An overlay position builder.
2564 */
2565 position() {
2566 return this._positionBuilder;
2567 }
2568 /**
2569 * Creates the DOM element for an overlay and appends it to the overlay container.
2570 * @returns Newly-created pane element
2571 */
2572 _createPaneElement(host) {
2573 const pane = this._document.createElement('div');
2574 pane.id = `cdk-overlay-${nextUniqueId++}`;
2575 pane.classList.add('cdk-overlay-pane');
2576 host.appendChild(pane);
2577 return pane;
2578 }
2579 /**
2580 * Creates the host element that wraps around an overlay
2581 * and can be used for advanced positioning.
2582 * @returns Newly-create host element.
2583 */
2584 _createHostElement() {
2585 const host = this._document.createElement('div');
2586 this._overlayContainer.getContainerElement().appendChild(host);
2587 return host;
2588 }
2589 /**
2590 * Create a DomPortalOutlet into which the overlay content can be loaded.
2591 * @param pane The DOM element to turn into a portal outlet.
2592 * @returns A portal outlet for the given DOM element.
2593 */
2594 _createPortalOutlet(pane) {
2595 // We have to resolve the ApplicationRef later in order to allow people
2596 // to use overlay-based providers during app initialization.
2597 if (!this._appRef) {
2598 this._appRef = this._injector.get(ApplicationRef);
2599 }
2600 return new DomPortalOutlet(pane, this._componentFactoryResolver, this._appRef, this._injector, this._document);
2601 }
2602}
2603Overlay.decorators = [
2604 { type: Injectable }
2605];
2606Overlay.ctorParameters = () => [
2607 { type: ScrollStrategyOptions },
2608 { type: OverlayContainer },
2609 { type: ComponentFactoryResolver },
2610 { type: OverlayPositionBuilder },
2611 { type: OverlayKeyboardDispatcher },
2612 { type: Injector },
2613 { type: NgZone },
2614 { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
2615 { type: Directionality },
2616 { type: Location },
2617 { type: OverlayOutsideClickDispatcher }
2618];
2619
2620/**
2621 * @license
2622 * Copyright Google LLC All Rights Reserved.
2623 *
2624 * Use of this source code is governed by an MIT-style license that can be
2625 * found in the LICENSE file at https://angular.io/license
2626 */
2627/** Default set of positions for the overlay. Follows the behavior of a dropdown. */
2628const defaultPositionList = [
2629 {
2630 originX: 'start',
2631 originY: 'bottom',
2632 overlayX: 'start',
2633 overlayY: 'top'
2634 },
2635 {
2636 originX: 'start',
2637 originY: 'top',
2638 overlayX: 'start',
2639 overlayY: 'bottom'
2640 },
2641 {
2642 originX: 'end',
2643 originY: 'top',
2644 overlayX: 'end',
2645 overlayY: 'bottom'
2646 },
2647 {
2648 originX: 'end',
2649 originY: 'bottom',
2650 overlayX: 'end',
2651 overlayY: 'top'
2652 }
2653];
2654/** Injection token that determines the scroll handling while the connected overlay is open. */
2655const CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY = new InjectionToken('cdk-connected-overlay-scroll-strategy');
2656/**
2657 * Directive applied to an element to make it usable as an origin for an Overlay using a
2658 * ConnectedPositionStrategy.
2659 */
2660class CdkOverlayOrigin {
2661 constructor(
2662 /** Reference to the element on which the directive is applied. */
2663 elementRef) {
2664 this.elementRef = elementRef;
2665 }
2666}
2667CdkOverlayOrigin.decorators = [
2668 { type: Directive, args: [{
2669 selector: '[cdk-overlay-origin], [overlay-origin], [cdkOverlayOrigin]',
2670 exportAs: 'cdkOverlayOrigin',
2671 },] }
2672];
2673CdkOverlayOrigin.ctorParameters = () => [
2674 { type: ElementRef }
2675];
2676/**
2677 * Directive to facilitate declarative creation of an
2678 * Overlay using a FlexibleConnectedPositionStrategy.
2679 */
2680class CdkConnectedOverlay {
2681 // TODO(jelbourn): inputs for size, scroll behavior, animation, etc.
2682 constructor(_overlay, templateRef, viewContainerRef, scrollStrategyFactory, _dir) {
2683 this._overlay = _overlay;
2684 this._dir = _dir;
2685 this._hasBackdrop = false;
2686 this._lockPosition = false;
2687 this._growAfterOpen = false;
2688 this._flexibleDimensions = false;
2689 this._push = false;
2690 this._backdropSubscription = Subscription.EMPTY;
2691 this._attachSubscription = Subscription.EMPTY;
2692 this._detachSubscription = Subscription.EMPTY;
2693 this._positionSubscription = Subscription.EMPTY;
2694 /** Margin between the overlay and the viewport edges. */
2695 this.viewportMargin = 0;
2696 /** Whether the overlay is open. */
2697 this.open = false;
2698 /** Whether the overlay can be closed by user interaction. */
2699 this.disableClose = false;
2700 /** Event emitted when the backdrop is clicked. */
2701 this.backdropClick = new EventEmitter();
2702 /** Event emitted when the position has changed. */
2703 this.positionChange = new EventEmitter();
2704 /** Event emitted when the overlay has been attached. */
2705 this.attach = new EventEmitter();
2706 /** Event emitted when the overlay has been detached. */
2707 this.detach = new EventEmitter();
2708 /** Emits when there are keyboard events that are targeted at the overlay. */
2709 this.overlayKeydown = new EventEmitter();
2710 /** Emits when there are mouse outside click events that are targeted at the overlay. */
2711 this.overlayOutsideClick = new EventEmitter();
2712 this._templatePortal = new TemplatePortal(templateRef, viewContainerRef);
2713 this._scrollStrategyFactory = scrollStrategyFactory;
2714 this.scrollStrategy = this._scrollStrategyFactory();
2715 }
2716 /** The offset in pixels for the overlay connection point on the x-axis */
2717 get offsetX() { return this._offsetX; }
2718 set offsetX(offsetX) {
2719 this._offsetX = offsetX;
2720 if (this._position) {
2721 this._updatePositionStrategy(this._position);
2722 }
2723 }
2724 /** The offset in pixels for the overlay connection point on the y-axis */
2725 get offsetY() { return this._offsetY; }
2726 set offsetY(offsetY) {
2727 this._offsetY = offsetY;
2728 if (this._position) {
2729 this._updatePositionStrategy(this._position);
2730 }
2731 }
2732 /** Whether or not the overlay should attach a backdrop. */
2733 get hasBackdrop() { return this._hasBackdrop; }
2734 set hasBackdrop(value) { this._hasBackdrop = coerceBooleanProperty(value); }
2735 /** Whether or not the overlay should be locked when scrolling. */
2736 get lockPosition() { return this._lockPosition; }
2737 set lockPosition(value) { this._lockPosition = coerceBooleanProperty(value); }
2738 /** Whether the overlay's width and height can be constrained to fit within the viewport. */
2739 get flexibleDimensions() { return this._flexibleDimensions; }
2740 set flexibleDimensions(value) {
2741 this._flexibleDimensions = coerceBooleanProperty(value);
2742 }
2743 /** Whether the overlay can grow after the initial open when flexible positioning is turned on. */
2744 get growAfterOpen() { return this._growAfterOpen; }
2745 set growAfterOpen(value) { this._growAfterOpen = coerceBooleanProperty(value); }
2746 /** Whether the overlay can be pushed on-screen if none of the provided positions fit. */
2747 get push() { return this._push; }
2748 set push(value) { this._push = coerceBooleanProperty(value); }
2749 /** The associated overlay reference. */
2750 get overlayRef() {
2751 return this._overlayRef;
2752 }
2753 /** The element's layout direction. */
2754 get dir() {
2755 return this._dir ? this._dir.value : 'ltr';
2756 }
2757 ngOnDestroy() {
2758 this._attachSubscription.unsubscribe();
2759 this._detachSubscription.unsubscribe();
2760 this._backdropSubscription.unsubscribe();
2761 this._positionSubscription.unsubscribe();
2762 if (this._overlayRef) {
2763 this._overlayRef.dispose();
2764 }
2765 }
2766 ngOnChanges(changes) {
2767 if (this._position) {
2768 this._updatePositionStrategy(this._position);
2769 this._overlayRef.updateSize({
2770 width: this.width,
2771 minWidth: this.minWidth,
2772 height: this.height,
2773 minHeight: this.minHeight,
2774 });
2775 if (changes['origin'] && this.open) {
2776 this._position.apply();
2777 }
2778 }
2779 if (changes['open']) {
2780 this.open ? this._attachOverlay() : this._detachOverlay();
2781 }
2782 }
2783 /** Creates an overlay */
2784 _createOverlay() {
2785 if (!this.positions || !this.positions.length) {
2786 this.positions = defaultPositionList;
2787 }
2788 const overlayRef = this._overlayRef = this._overlay.create(this._buildConfig());
2789 this._attachSubscription = overlayRef.attachments().subscribe(() => this.attach.emit());
2790 this._detachSubscription = overlayRef.detachments().subscribe(() => this.detach.emit());
2791 overlayRef.keydownEvents().subscribe((event) => {
2792 this.overlayKeydown.next(event);
2793 if (event.keyCode === ESCAPE && !this.disableClose && !hasModifierKey(event)) {
2794 event.preventDefault();
2795 this._detachOverlay();
2796 }
2797 });
2798 this._overlayRef.outsidePointerEvents().subscribe((event) => {
2799 this.overlayOutsideClick.next(event);
2800 });
2801 }
2802 /** Builds the overlay config based on the directive's inputs */
2803 _buildConfig() {
2804 const positionStrategy = this._position =
2805 this.positionStrategy || this._createPositionStrategy();
2806 const overlayConfig = new OverlayConfig({
2807 direction: this._dir,
2808 positionStrategy,
2809 scrollStrategy: this.scrollStrategy,
2810 hasBackdrop: this.hasBackdrop
2811 });
2812 if (this.width || this.width === 0) {
2813 overlayConfig.width = this.width;
2814 }
2815 if (this.height || this.height === 0) {
2816 overlayConfig.height = this.height;
2817 }
2818 if (this.minWidth || this.minWidth === 0) {
2819 overlayConfig.minWidth = this.minWidth;
2820 }
2821 if (this.minHeight || this.minHeight === 0) {
2822 overlayConfig.minHeight = this.minHeight;
2823 }
2824 if (this.backdropClass) {
2825 overlayConfig.backdropClass = this.backdropClass;
2826 }
2827 if (this.panelClass) {
2828 overlayConfig.panelClass = this.panelClass;
2829 }
2830 return overlayConfig;
2831 }
2832 /** Updates the state of a position strategy, based on the values of the directive inputs. */
2833 _updatePositionStrategy(positionStrategy) {
2834 const positions = this.positions.map(currentPosition => ({
2835 originX: currentPosition.originX,
2836 originY: currentPosition.originY,
2837 overlayX: currentPosition.overlayX,
2838 overlayY: currentPosition.overlayY,
2839 offsetX: currentPosition.offsetX || this.offsetX,
2840 offsetY: currentPosition.offsetY || this.offsetY,
2841 panelClass: currentPosition.panelClass || undefined,
2842 }));
2843 return positionStrategy
2844 .setOrigin(this.origin.elementRef)
2845 .withPositions(positions)
2846 .withFlexibleDimensions(this.flexibleDimensions)
2847 .withPush(this.push)
2848 .withGrowAfterOpen(this.growAfterOpen)
2849 .withViewportMargin(this.viewportMargin)
2850 .withLockedPosition(this.lockPosition)
2851 .withTransformOriginOn(this.transformOriginSelector);
2852 }
2853 /** Returns the position strategy of the overlay to be set on the overlay config */
2854 _createPositionStrategy() {
2855 const strategy = this._overlay.position().flexibleConnectedTo(this.origin.elementRef);
2856 this._updatePositionStrategy(strategy);
2857 return strategy;
2858 }
2859 /** Attaches the overlay and subscribes to backdrop clicks if backdrop exists */
2860 _attachOverlay() {
2861 if (!this._overlayRef) {
2862 this._createOverlay();
2863 }
2864 else {
2865 // Update the overlay size, in case the directive's inputs have changed
2866 this._overlayRef.getConfig().hasBackdrop = this.hasBackdrop;
2867 }
2868 if (!this._overlayRef.hasAttached()) {
2869 this._overlayRef.attach(this._templatePortal);
2870 }
2871 if (this.hasBackdrop) {
2872 this._backdropSubscription = this._overlayRef.backdropClick().subscribe(event => {
2873 this.backdropClick.emit(event);
2874 });
2875 }
2876 else {
2877 this._backdropSubscription.unsubscribe();
2878 }
2879 this._positionSubscription.unsubscribe();
2880 // Only subscribe to `positionChanges` if requested, because putting
2881 // together all the information for it can be expensive.
2882 if (this.positionChange.observers.length > 0) {
2883 this._positionSubscription = this._position.positionChanges
2884 .pipe(takeWhile(() => this.positionChange.observers.length > 0))
2885 .subscribe(position => {
2886 this.positionChange.emit(position);
2887 if (this.positionChange.observers.length === 0) {
2888 this._positionSubscription.unsubscribe();
2889 }
2890 });
2891 }
2892 }
2893 /** Detaches the overlay and unsubscribes to backdrop clicks if backdrop exists */
2894 _detachOverlay() {
2895 if (this._overlayRef) {
2896 this._overlayRef.detach();
2897 }
2898 this._backdropSubscription.unsubscribe();
2899 this._positionSubscription.unsubscribe();
2900 }
2901}
2902CdkConnectedOverlay.decorators = [
2903 { type: Directive, args: [{
2904 selector: '[cdk-connected-overlay], [connected-overlay], [cdkConnectedOverlay]',
2905 exportAs: 'cdkConnectedOverlay'
2906 },] }
2907];
2908CdkConnectedOverlay.ctorParameters = () => [
2909 { type: Overlay },
2910 { type: TemplateRef },
2911 { type: ViewContainerRef },
2912 { type: undefined, decorators: [{ type: Inject, args: [CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY,] }] },
2913 { type: Directionality, decorators: [{ type: Optional }] }
2914];
2915CdkConnectedOverlay.propDecorators = {
2916 origin: [{ type: Input, args: ['cdkConnectedOverlayOrigin',] }],
2917 positions: [{ type: Input, args: ['cdkConnectedOverlayPositions',] }],
2918 positionStrategy: [{ type: Input, args: ['cdkConnectedOverlayPositionStrategy',] }],
2919 offsetX: [{ type: Input, args: ['cdkConnectedOverlayOffsetX',] }],
2920 offsetY: [{ type: Input, args: ['cdkConnectedOverlayOffsetY',] }],
2921 width: [{ type: Input, args: ['cdkConnectedOverlayWidth',] }],
2922 height: [{ type: Input, args: ['cdkConnectedOverlayHeight',] }],
2923 minWidth: [{ type: Input, args: ['cdkConnectedOverlayMinWidth',] }],
2924 minHeight: [{ type: Input, args: ['cdkConnectedOverlayMinHeight',] }],
2925 backdropClass: [{ type: Input, args: ['cdkConnectedOverlayBackdropClass',] }],
2926 panelClass: [{ type: Input, args: ['cdkConnectedOverlayPanelClass',] }],
2927 viewportMargin: [{ type: Input, args: ['cdkConnectedOverlayViewportMargin',] }],
2928 scrollStrategy: [{ type: Input, args: ['cdkConnectedOverlayScrollStrategy',] }],
2929 open: [{ type: Input, args: ['cdkConnectedOverlayOpen',] }],
2930 disableClose: [{ type: Input, args: ['cdkConnectedOverlayDisableClose',] }],
2931 transformOriginSelector: [{ type: Input, args: ['cdkConnectedOverlayTransformOriginOn',] }],
2932 hasBackdrop: [{ type: Input, args: ['cdkConnectedOverlayHasBackdrop',] }],
2933 lockPosition: [{ type: Input, args: ['cdkConnectedOverlayLockPosition',] }],
2934 flexibleDimensions: [{ type: Input, args: ['cdkConnectedOverlayFlexibleDimensions',] }],
2935 growAfterOpen: [{ type: Input, args: ['cdkConnectedOverlayGrowAfterOpen',] }],
2936 push: [{ type: Input, args: ['cdkConnectedOverlayPush',] }],
2937 backdropClick: [{ type: Output }],
2938 positionChange: [{ type: Output }],
2939 attach: [{ type: Output }],
2940 detach: [{ type: Output }],
2941 overlayKeydown: [{ type: Output }],
2942 overlayOutsideClick: [{ type: Output }]
2943};
2944/** @docs-private */
2945function CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY_PROVIDER_FACTORY(overlay) {
2946 return () => overlay.scrollStrategies.reposition();
2947}
2948/** @docs-private */
2949const CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY_PROVIDER = {
2950 provide: CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY,
2951 deps: [Overlay],
2952 useFactory: CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY_PROVIDER_FACTORY,
2953};
2954
2955/**
2956 * @license
2957 * Copyright Google LLC All Rights Reserved.
2958 *
2959 * Use of this source code is governed by an MIT-style license that can be
2960 * found in the LICENSE file at https://angular.io/license
2961 */
2962class OverlayModule {
2963}
2964OverlayModule.decorators = [
2965 { type: NgModule, args: [{
2966 imports: [BidiModule, PortalModule, ScrollingModule],
2967 exports: [CdkConnectedOverlay, CdkOverlayOrigin, ScrollingModule],
2968 declarations: [CdkConnectedOverlay, CdkOverlayOrigin],
2969 providers: [
2970 Overlay,
2971 CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY_PROVIDER,
2972 ],
2973 },] }
2974];
2975
2976/**
2977 * @license
2978 * Copyright Google LLC All Rights Reserved.
2979 *
2980 * Use of this source code is governed by an MIT-style license that can be
2981 * found in the LICENSE file at https://angular.io/license
2982 */
2983
2984/**
2985 * @license
2986 * Copyright Google LLC All Rights Reserved.
2987 *
2988 * Use of this source code is governed by an MIT-style license that can be
2989 * found in the LICENSE file at https://angular.io/license
2990 */
2991/**
2992 * Alternative to OverlayContainer that supports correct displaying of overlay elements in
2993 * Fullscreen mode
2994 * https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullScreen
2995 *
2996 * Should be provided in the root component.
2997 */
2998class FullscreenOverlayContainer extends OverlayContainer {
2999 constructor(_document, platform) {
3000 super(_document, platform);
3001 }
3002 ngOnDestroy() {
3003 super.ngOnDestroy();
3004 if (this._fullScreenEventName && this._fullScreenListener) {
3005 this._document.removeEventListener(this._fullScreenEventName, this._fullScreenListener);
3006 }
3007 }
3008 _createContainer() {
3009 super._createContainer();
3010 this._adjustParentForFullscreenChange();
3011 this._addFullscreenChangeListener(() => this._adjustParentForFullscreenChange());
3012 }
3013 _adjustParentForFullscreenChange() {
3014 if (!this._containerElement) {
3015 return;
3016 }
3017 const fullscreenElement = this.getFullscreenElement();
3018 const parent = fullscreenElement || this._document.body;
3019 parent.appendChild(this._containerElement);
3020 }
3021 _addFullscreenChangeListener(fn) {
3022 const eventName = this._getEventName();
3023 if (eventName) {
3024 if (this._fullScreenListener) {
3025 this._document.removeEventListener(eventName, this._fullScreenListener);
3026 }
3027 this._document.addEventListener(eventName, fn);
3028 this._fullScreenListener = fn;
3029 }
3030 }
3031 _getEventName() {
3032 if (!this._fullScreenEventName) {
3033 const _document = this._document;
3034 if (_document.fullscreenEnabled) {
3035 this._fullScreenEventName = 'fullscreenchange';
3036 }
3037 else if (_document.webkitFullscreenEnabled) {
3038 this._fullScreenEventName = 'webkitfullscreenchange';
3039 }
3040 else if (_document.mozFullScreenEnabled) {
3041 this._fullScreenEventName = 'mozfullscreenchange';
3042 }
3043 else if (_document.msFullscreenEnabled) {
3044 this._fullScreenEventName = 'MSFullscreenChange';
3045 }
3046 }
3047 return this._fullScreenEventName;
3048 }
3049 /**
3050 * When the page is put into fullscreen mode, a specific element is specified.
3051 * Only that element and its children are visible when in fullscreen mode.
3052 */
3053 getFullscreenElement() {
3054 const _document = this._document;
3055 return _document.fullscreenElement ||
3056 _document.webkitFullscreenElement ||
3057 _document.mozFullScreenElement ||
3058 _document.msFullscreenElement ||
3059 null;
3060 }
3061}
3062FullscreenOverlayContainer.ɵprov = i0.ɵɵdefineInjectable({ factory: function FullscreenOverlayContainer_Factory() { return new FullscreenOverlayContainer(i0.ɵɵinject(i1$1.DOCUMENT), i0.ɵɵinject(i2.Platform)); }, token: FullscreenOverlayContainer, providedIn: "root" });
3063FullscreenOverlayContainer.decorators = [
3064 { type: Injectable, args: [{ providedIn: 'root' },] }
3065];
3066FullscreenOverlayContainer.ctorParameters = () => [
3067 { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
3068 { type: Platform }
3069];
3070
3071/**
3072 * @license
3073 * Copyright Google LLC All Rights Reserved.
3074 *
3075 * Use of this source code is governed by an MIT-style license that can be
3076 * found in the LICENSE file at https://angular.io/license
3077 */
3078
3079/**
3080 * Generated bundle index. Do not edit.
3081 */
3082
3083export { BlockScrollStrategy, CdkConnectedOverlay, CdkOverlayOrigin, CloseScrollStrategy, ConnectedOverlayPositionChange, ConnectedPositionStrategy, ConnectionPositionPair, FlexibleConnectedPositionStrategy, FullscreenOverlayContainer, GlobalPositionStrategy, NoopScrollStrategy, Overlay, OverlayConfig, OverlayContainer, OverlayKeyboardDispatcher, OverlayModule, OverlayOutsideClickDispatcher, OverlayPositionBuilder, OverlayRef, RepositionScrollStrategy, ScrollStrategyOptions, ScrollingVisibility, validateHorizontalPosition, validateVerticalPosition, CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY as ɵangular_material_src_cdk_overlay_overlay_a, CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY_PROVIDER_FACTORY as ɵangular_material_src_cdk_overlay_overlay_b, CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY_PROVIDER as ɵangular_material_src_cdk_overlay_overlay_c, BaseOverlayDispatcher as ɵangular_material_src_cdk_overlay_overlay_d };
3084//# sourceMappingURL=overlay.js.map
Note: See TracBrowser for help on using the repository browser.