@dugararchit/cdk 0.0.0-dugararchit

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