overlay.mjs 137 KB

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