@spectrum-web-components/overlay 0.15.0 → 0.15.2

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 (48) hide show
  1. package/active-overlay.d.ts +6 -0
  2. package/active-overlay.js +14 -0
  3. package/active-overlay.js.map +1 -0
  4. package/custom-elements.json +6 -6
  5. package/overlay-trigger.d.ts +6 -0
  6. package/overlay-trigger.js +14 -0
  7. package/overlay-trigger.js.map +1 -0
  8. package/package.json +6 -6
  9. package/src/ActiveOverlay.d.ts +77 -0
  10. package/src/ActiveOverlay.js +436 -0
  11. package/src/ActiveOverlay.js.map +1 -0
  12. package/src/OverlayTrigger.d.ts +66 -0
  13. package/src/OverlayTrigger.js +310 -0
  14. package/src/OverlayTrigger.js.map +1 -0
  15. package/src/VirtualTrigger.d.ts +7 -0
  16. package/src/VirtualTrigger.js +40 -0
  17. package/src/VirtualTrigger.js.map +1 -0
  18. package/src/active-overlay.css.d.ts +2 -0
  19. package/src/active-overlay.css.js +21 -0
  20. package/src/active-overlay.css.js.map +1 -0
  21. package/src/index.d.ts +6 -0
  22. package/src/index.js +18 -0
  23. package/src/index.js.map +1 -0
  24. package/src/loader.d.ts +2 -0
  25. package/src/loader.js +16 -0
  26. package/src/loader.js.map +1 -0
  27. package/src/overlay-stack.d.ts +46 -0
  28. package/src/overlay-stack.js +449 -0
  29. package/src/overlay-stack.js.map +1 -0
  30. package/src/overlay-timer.d.ts +22 -0
  31. package/src/overlay-timer.js +89 -0
  32. package/src/overlay-timer.js.map +1 -0
  33. package/src/overlay-trigger.css.d.ts +2 -0
  34. package/src/overlay-trigger.css.js +17 -0
  35. package/src/overlay-trigger.css.js.map +1 -0
  36. package/src/overlay-types.d.ts +52 -0
  37. package/src/overlay-types.js +13 -0
  38. package/src/overlay-types.js.map +1 -0
  39. package/src/overlay.d.ts +59 -0
  40. package/src/overlay.js +119 -0
  41. package/src/overlay.js.map +1 -0
  42. package/stories/overlay-story-components.js +292 -0
  43. package/stories/overlay-story-components.js.map +1 -0
  44. package/stories/overlay.stories.js +805 -0
  45. package/stories/overlay.stories.js.map +1 -0
  46. package/sync/overlay-trigger.d.ts +1 -0
  47. package/sync/overlay-trigger.js +18 -0
  48. package/sync/overlay-trigger.js.map +1 -0
@@ -0,0 +1,6 @@
1
+ import { ActiveOverlay } from './src/ActiveOverlay.js';
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ 'active-overlay': ActiveOverlay;
5
+ }
6
+ }
@@ -0,0 +1,14 @@
1
+ /*
2
+ Copyright 2020 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ import { ActiveOverlay } from './src/ActiveOverlay.js';
13
+ customElements.define('active-overlay', ActiveOverlay);
14
+ //# sourceMappingURL=active-overlay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"active-overlay.js","sourceRoot":"","sources":["active-overlay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,cAAc,CAAC,MAAM,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { ActiveOverlay } from './src/ActiveOverlay.js';\n\ncustomElements.define('active-overlay', ActiveOverlay);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'active-overlay': ActiveOverlay;\n }\n}\n"]}
@@ -32,6 +32,12 @@
32
32
  }
33
33
  ]
34
34
  },
35
+ {
36
+ "kind": "javascript-module",
37
+ "path": "sync/overlay-trigger.ts",
38
+ "declarations": [],
39
+ "exports": []
40
+ },
35
41
  {
36
42
  "kind": "javascript-module",
37
43
  "path": "src/ActiveOverlay.ts",
@@ -2059,12 +2065,6 @@
2059
2065
  }
2060
2066
  }
2061
2067
  ]
2062
- },
2063
- {
2064
- "kind": "javascript-module",
2065
- "path": "sync/overlay-trigger.ts",
2066
- "declarations": [],
2067
- "exports": []
2068
2068
  }
2069
2069
  ]
2070
2070
  }
@@ -0,0 +1,6 @@
1
+ import { OverlayTrigger } from './src/OverlayTrigger.js';
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ 'overlay-trigger': OverlayTrigger;
5
+ }
6
+ }
@@ -0,0 +1,14 @@
1
+ /*
2
+ Copyright 2020 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ import { OverlayTrigger } from './src/OverlayTrigger.js';
13
+ customElements.define('overlay-trigger', OverlayTrigger);
14
+ //# sourceMappingURL=overlay-trigger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"overlay-trigger.js","sourceRoot":"","sources":["overlay-trigger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,cAAc,CAAC,MAAM,CAAC,iBAAiB,EAAE,cAAc,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { OverlayTrigger } from './src/OverlayTrigger.js';\n\ncustomElements.define('overlay-trigger', OverlayTrigger);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'overlay-trigger': OverlayTrigger;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/overlay",
3
- "version": "0.15.0",
3
+ "version": "0.15.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -49,10 +49,10 @@
49
49
  ],
50
50
  "dependencies": {
51
51
  "@floating-ui/dom": "^0.2.0",
52
- "@spectrum-web-components/action-button": "^0.8.0",
53
- "@spectrum-web-components/base": "^0.5.3",
54
- "@spectrum-web-components/shared": "^0.13.5",
55
- "@spectrum-web-components/theme": "^0.10.0",
52
+ "@spectrum-web-components/action-button": "^0.8.1",
53
+ "@spectrum-web-components/base": "^0.5.4",
54
+ "@spectrum-web-components/shared": "^0.13.6",
55
+ "@spectrum-web-components/theme": "^0.10.1",
56
56
  "tslib": "^2.0.0"
57
57
  },
58
58
  "types": "./src/index.d.ts",
@@ -63,5 +63,5 @@
63
63
  "./sync/overlay-trigger.js",
64
64
  "./stories/overlay-story-components.js"
65
65
  ],
66
- "gitHead": "57aba8030b6af96af4015a0aa830e342a17dc219"
66
+ "gitHead": "caf12727e7f91dcf961e1fadacc727eea9ece27b"
67
67
  }
@@ -0,0 +1,77 @@
1
+ import { CSSResultArray, PropertyValues, SpectrumElement, TemplateResult } from '@spectrum-web-components/base';
2
+ import type { Color, Scale } from '@spectrum-web-components/theme/src/Theme.js';
3
+ import { OverlayOpenDetail, Placement, TriggerInteractions } from './overlay-types.js';
4
+ import type { VirtualTrigger } from './VirtualTrigger.js';
5
+ export interface PositionResult {
6
+ arrowOffsetLeft: number;
7
+ arrowOffsetTop: number;
8
+ maxHeight: number;
9
+ placement: string;
10
+ positionLeft: number;
11
+ positionTop: number;
12
+ }
13
+ declare type OverlayStateType = 'idle' | 'active' | 'hiding' | 'dispose' | 'disposed';
14
+ declare type ContentAnimation = 'sp-overlay-fade-in' | 'sp-overlay-fade-out';
15
+ /**
16
+ * @element active-overlay
17
+ *
18
+ * @slot - content to display in the overlay
19
+ */
20
+ export declare class ActiveOverlay extends SpectrumElement {
21
+ overlayContent: HTMLElement;
22
+ overlayContentTip?: HTMLElement;
23
+ trigger: HTMLElement;
24
+ virtualTrigger?: VirtualTrigger;
25
+ protected childrenReady: Promise<unknown[]>;
26
+ _state: OverlayStateType;
27
+ get state(): OverlayStateType;
28
+ set state(state: OverlayStateType);
29
+ animating: boolean;
30
+ placement?: Placement;
31
+ theme: {
32
+ color?: Color;
33
+ scale?: Scale;
34
+ lang?: string;
35
+ };
36
+ receivesFocus?: 'auto';
37
+ tabbingAway: boolean;
38
+ private originalPlacement?;
39
+ private restoreContent?;
40
+ focus(): void;
41
+ private get hasTheme();
42
+ offset: number;
43
+ skidding: number;
44
+ interaction: TriggerInteractions;
45
+ private positionAnimationFrame;
46
+ private timeout?;
47
+ static get styles(): CSSResultArray;
48
+ constructor();
49
+ private _modalRoot?;
50
+ get hasModalRoot(): boolean;
51
+ feature(): void;
52
+ obscure(nextOverlayInteraction: TriggerInteractions): ActiveOverlay | undefined;
53
+ firstUpdated(changedProperties: PropertyValues): Promise<void>;
54
+ openCallback(): Promise<void>;
55
+ private open;
56
+ private extractDetail;
57
+ dispose(): void;
58
+ private stealOverlayContent;
59
+ private willNotifyClosed;
60
+ private returnOverlayContent;
61
+ private initialHeight;
62
+ private isConstrained;
63
+ updateOverlayPosition: () => Promise<void>;
64
+ hide(animated?: boolean): Promise<void>;
65
+ private schedulePositionUpdate;
66
+ private onSlotChange;
67
+ handleInlineTriggerKeydown: (event: KeyboardEvent) => void;
68
+ applyContentAnimation(animation: ContentAnimation): Promise<boolean>;
69
+ renderTheme(content: TemplateResult): TemplateResult;
70
+ render(): TemplateResult;
71
+ static create(details: OverlayOpenDetail): ActiveOverlay;
72
+ private stealOverlayContentPromise;
73
+ private stealOverlayContentResolver;
74
+ protected getUpdateComplete(): Promise<boolean>;
75
+ disconnectedCallback(): void;
76
+ }
77
+ export {};
@@ -0,0 +1,436 @@
1
+ /*
2
+ Copyright 2020 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ import { __decorate } from "tslib";
13
+ import { html, SpectrumElement, } from '@spectrum-web-components/base';
14
+ import { ifDefined } from '@spectrum-web-components/base/src/directives.js';
15
+ import { property } from '@spectrum-web-components/base/src/decorators.js';
16
+ import { reparentChildren } from '@spectrum-web-components/shared/src/reparent-children.js';
17
+ import { firstFocusableIn } from '@spectrum-web-components/shared/src/first-focusable-in.js';
18
+ import styles from './active-overlay.css.js';
19
+ import { arrow, computePosition, flip, offset, shift, size, } from '@floating-ui/dom';
20
+ const stateMachine = {
21
+ initial: 'idle',
22
+ states: {
23
+ idle: {
24
+ on: {
25
+ active: 'active',
26
+ },
27
+ },
28
+ active: {
29
+ on: {
30
+ hiding: 'hiding',
31
+ idle: 'idle',
32
+ },
33
+ },
34
+ hiding: {
35
+ on: {
36
+ dispose: 'dispose',
37
+ },
38
+ },
39
+ dispose: {
40
+ on: {
41
+ disposed: 'disposed',
42
+ },
43
+ },
44
+ disposed: {
45
+ on: {},
46
+ },
47
+ },
48
+ };
49
+ const stateTransition = (state, event) => {
50
+ if (!state)
51
+ return stateMachine.initial;
52
+ /* c8 ignore next */
53
+ if (!event)
54
+ return state;
55
+ return stateMachine.states[state].on[event] || state;
56
+ };
57
+ const parentOverlayOf = (el) => {
58
+ const closestOverlay = el.closest('active-overlay');
59
+ if (closestOverlay) {
60
+ return closestOverlay;
61
+ }
62
+ const rootNode = el.getRootNode();
63
+ if (rootNode.host) {
64
+ return parentOverlayOf(rootNode.host);
65
+ }
66
+ return null;
67
+ };
68
+ /**
69
+ * @element active-overlay
70
+ *
71
+ * @slot - content to display in the overlay
72
+ */
73
+ export class ActiveOverlay extends SpectrumElement {
74
+ constructor() {
75
+ super();
76
+ this._state = stateTransition();
77
+ this.animating = false;
78
+ this.theme = {};
79
+ this.tabbingAway = false;
80
+ this.offset = 6;
81
+ this.skidding = 0;
82
+ this.interaction = 'hover';
83
+ this.positionAnimationFrame = 0;
84
+ this.willNotifyClosed = false;
85
+ this.isConstrained = false;
86
+ this.updateOverlayPosition = async () => {
87
+ if (!this.placement || this.placement === 'none') {
88
+ return;
89
+ }
90
+ await (document.fonts ? document.fonts.ready : Promise.resolve());
91
+ function roundByDPR(num) {
92
+ const dpr = window.devicePixelRatio || 1;
93
+ return Math.round(num * dpr) / dpr || -10000;
94
+ }
95
+ // See: https://spectrum.adobe.com/page/popover/#Container-padding
96
+ const REQUIRED_DISTANCE_TO_EDGE = 8;
97
+ // See: https://github.com/adobe/spectrum-web-components/issues/910
98
+ const MIN_OVERLAY_HEIGHT = 100;
99
+ const middleware = [
100
+ offset({
101
+ mainAxis: this.offset,
102
+ crossAxis: this.skidding,
103
+ }),
104
+ flip({
105
+ fallbackStrategy: 'initialPlacement',
106
+ }),
107
+ shift({ padding: REQUIRED_DISTANCE_TO_EDGE }),
108
+ size({
109
+ padding: REQUIRED_DISTANCE_TO_EDGE,
110
+ apply: ({ width, height, floating }) => {
111
+ const maxHeight = Math.max(MIN_OVERLAY_HEIGHT, Math.floor(height));
112
+ const actualHeight = floating.height;
113
+ this.initialHeight = !this.isConstrained
114
+ ? actualHeight
115
+ : this.initialHeight || actualHeight;
116
+ this.isConstrained =
117
+ actualHeight < this.initialHeight ||
118
+ maxHeight <= actualHeight;
119
+ const appliedHeight = this.isConstrained
120
+ ? `${maxHeight}px`
121
+ : '';
122
+ Object.assign(this.style, {
123
+ maxWidth: `${Math.floor(width)}px`,
124
+ maxHeight: appliedHeight,
125
+ height: appliedHeight,
126
+ });
127
+ },
128
+ }),
129
+ ];
130
+ if (this.overlayContentTip) {
131
+ middleware.push(arrow({ element: this.overlayContentTip }));
132
+ }
133
+ const { x, y, placement, middlewareData } = await computePosition(this.virtualTrigger || this.trigger, this, {
134
+ placement: this.placement,
135
+ middleware,
136
+ });
137
+ Object.assign(this.style, {
138
+ top: '0px',
139
+ left: '0px',
140
+ transform: `translate(${roundByDPR(x)}px, ${roundByDPR(y)}px)`,
141
+ });
142
+ if (placement !== this.getAttribute('actual-placement')) {
143
+ this.setAttribute('actual-placement', placement);
144
+ this.overlayContent.setAttribute('placement', placement);
145
+ }
146
+ if (this.overlayContentTip && middlewareData.arrow) {
147
+ const { x: arrowX, y: arrowY } = middlewareData.arrow;
148
+ Object.assign(this.overlayContentTip.style, {
149
+ left: arrowX != null ? `${roundByDPR(arrowX)}px` : '',
150
+ top: arrowY != null ? `${roundByDPR(arrowY)}px` : '',
151
+ right: '',
152
+ bottom: '',
153
+ });
154
+ }
155
+ };
156
+ this.handleInlineTriggerKeydown = (event) => {
157
+ const { code, shiftKey } = event;
158
+ /* c8 ignore next */
159
+ if (code !== 'Tab')
160
+ return;
161
+ if (shiftKey) {
162
+ this.tabbingAway = true;
163
+ this.dispatchEvent(new Event('close'));
164
+ return;
165
+ }
166
+ event.stopPropagation();
167
+ event.preventDefault();
168
+ this.focus();
169
+ };
170
+ this.stealOverlayContentPromise = Promise.resolve();
171
+ this.stealOverlayContentPromise = new Promise((res) => (this.stealOverlayContentResolver = res));
172
+ }
173
+ get state() {
174
+ return this._state;
175
+ }
176
+ set state(state) {
177
+ const nextState = stateTransition(this.state, state);
178
+ if (nextState === this.state) {
179
+ return;
180
+ }
181
+ this._state = nextState;
182
+ if (this.state === 'active' || this.state === 'hiding') {
183
+ this.setAttribute('state', this.state);
184
+ }
185
+ else {
186
+ this.removeAttribute('state');
187
+ }
188
+ }
189
+ focus() {
190
+ const firstFocusable = firstFocusableIn(this);
191
+ if (firstFocusable) {
192
+ firstFocusable.focus();
193
+ /* c8 ignore next 3 */
194
+ }
195
+ else {
196
+ super.focus();
197
+ }
198
+ this.removeAttribute('tabindex');
199
+ }
200
+ get hasTheme() {
201
+ return !!this.theme.color || !!this.theme.scale || !!this.theme.lang;
202
+ }
203
+ static get styles() {
204
+ return [styles];
205
+ }
206
+ get hasModalRoot() {
207
+ return !!this._modalRoot;
208
+ }
209
+ feature() {
210
+ this.tabIndex = -1;
211
+ const parentOverlay = parentOverlayOf(this.trigger);
212
+ const parentIsModal = parentOverlay && parentOverlay.slot === 'open';
213
+ if (parentIsModal) {
214
+ this._modalRoot = parentOverlay._modalRoot || parentOverlay;
215
+ }
216
+ // If an overlay it triggered from within a "modal" overlay, it needs to continue
217
+ // to act like one to get treated correctly in regards to tab trapping.
218
+ if (this.interaction === 'modal' || this._modalRoot) {
219
+ this.slot = 'open';
220
+ if (this.interaction === 'modal') {
221
+ this.setAttribute('aria-modal', 'true');
222
+ }
223
+ // If this isn't a modal root, walk up the overlays to the next modal root
224
+ // and "feature" each on of the intervening overlays.
225
+ if (this._modalRoot) {
226
+ parentOverlay === null || parentOverlay === void 0 ? void 0 : parentOverlay.feature();
227
+ }
228
+ }
229
+ }
230
+ obscure(nextOverlayInteraction) {
231
+ if (this.slot && nextOverlayInteraction === 'modal') {
232
+ this.removeAttribute('slot');
233
+ this.removeAttribute('aria-modal');
234
+ // Obscure upto and including the next modal root.
235
+ if (this.interaction !== 'modal') {
236
+ const parentOverlay = parentOverlayOf(this.trigger);
237
+ this._modalRoot = parentOverlay === null || parentOverlay === void 0 ? void 0 : parentOverlay.obscure(nextOverlayInteraction);
238
+ return this._modalRoot;
239
+ }
240
+ return this;
241
+ }
242
+ return undefined;
243
+ }
244
+ async firstUpdated(changedProperties) {
245
+ super.firstUpdated(changedProperties);
246
+ /* c8 ignore next */
247
+ if (!this.overlayContent || !this.trigger)
248
+ return;
249
+ this.stealOverlayContent(this.overlayContent);
250
+ this.state = 'active';
251
+ this.feature();
252
+ if (this.placement === 'none') {
253
+ this.style.setProperty('--swc-visual-viewport-height', `${window.innerHeight}px`);
254
+ }
255
+ else if (this.placement) {
256
+ await this.updateOverlayPosition();
257
+ document.addEventListener('sp-update-overlays', this.updateOverlayPosition);
258
+ window.addEventListener('scroll', this.updateOverlayPosition);
259
+ }
260
+ const actions = [];
261
+ if (this.placement && this.placement !== 'none') {
262
+ actions.push(this.applyContentAnimation('sp-overlay-fade-in'));
263
+ }
264
+ if (typeof this.overlayContent.updateComplete !==
265
+ 'undefined') {
266
+ actions.push(this.overlayContent.updateComplete);
267
+ }
268
+ this.childrenReady = Promise.all(actions);
269
+ }
270
+ async openCallback() {
271
+ await this.updateComplete;
272
+ if (this.receivesFocus) {
273
+ this.focus();
274
+ }
275
+ this.trigger.dispatchEvent(new CustomEvent('sp-opened', {
276
+ bubbles: true,
277
+ composed: true,
278
+ cancelable: true,
279
+ detail: {
280
+ interaction: this.interaction,
281
+ },
282
+ }));
283
+ }
284
+ open(openDetail) {
285
+ this.extractDetail(openDetail);
286
+ }
287
+ extractDetail(detail) {
288
+ this.overlayContent = detail.content;
289
+ this.overlayContentTip = detail.contentTip;
290
+ this.trigger = detail.trigger;
291
+ this.virtualTrigger = detail.virtualTrigger;
292
+ this.placement = detail.placement;
293
+ this.offset = detail.offset;
294
+ this.skidding = detail.skidding || 0;
295
+ this.interaction = detail.interaction;
296
+ this.theme = detail.theme;
297
+ this.receivesFocus = detail.receivesFocus;
298
+ }
299
+ dispose() {
300
+ /* c8 ignore next */
301
+ if (this.state !== 'dispose')
302
+ return;
303
+ /* c8 ignore next 4 */
304
+ if (this.timeout) {
305
+ clearTimeout(this.timeout);
306
+ delete this.timeout;
307
+ }
308
+ this.trigger.removeEventListener('keydown', this.handleInlineTriggerKeydown);
309
+ this.returnOverlayContent();
310
+ this.state = 'disposed';
311
+ if (this.willNotifyClosed) {
312
+ this.overlayContent.dispatchEvent(new Event('sp-overlay-closed'));
313
+ this.willNotifyClosed = false;
314
+ }
315
+ }
316
+ stealOverlayContent(element) {
317
+ this.originalPlacement = element.getAttribute('placement');
318
+ this.restoreContent = reparentChildren([element], this, (el) => {
319
+ const slotName = el.slot;
320
+ const placement = el.placement;
321
+ el.removeAttribute('slot');
322
+ return (el) => {
323
+ el.slot = slotName;
324
+ el.placement = placement;
325
+ };
326
+ });
327
+ this.stealOverlayContentResolver();
328
+ }
329
+ returnOverlayContent() {
330
+ /* c8 ignore next */
331
+ if (!this.restoreContent)
332
+ return;
333
+ const [element] = this.restoreContent();
334
+ this.restoreContent = undefined;
335
+ this.willNotifyClosed = true;
336
+ if (this.originalPlacement) {
337
+ element.setAttribute('placement', this.originalPlacement);
338
+ delete this.originalPlacement;
339
+ }
340
+ }
341
+ async hide(animated = true) {
342
+ this.state = 'hiding';
343
+ if (animated) {
344
+ await this.applyContentAnimation('sp-overlay-fade-out');
345
+ }
346
+ this.state = 'dispose';
347
+ }
348
+ schedulePositionUpdate() {
349
+ // Edge needs a little time to update the DOM before computing the layout
350
+ cancelAnimationFrame(this.positionAnimationFrame);
351
+ this.positionAnimationFrame = requestAnimationFrame(() => this.updateOverlayPosition());
352
+ }
353
+ onSlotChange() {
354
+ this.schedulePositionUpdate();
355
+ }
356
+ applyContentAnimation(animation) {
357
+ if (this.placement === 'none') {
358
+ return Promise.resolve(true);
359
+ }
360
+ return new Promise((resolve) => {
361
+ const contents = this.shadowRoot.querySelector('#contents');
362
+ const doneHandler = (event) => {
363
+ if (animation !== event.animationName)
364
+ return;
365
+ contents.removeEventListener('animationend', doneHandler);
366
+ contents.removeEventListener('animationcancel', doneHandler);
367
+ this.animating = false;
368
+ resolve(event.type === 'animationcancel');
369
+ };
370
+ contents.addEventListener('animationend', doneHandler);
371
+ contents.addEventListener('animationcancel', doneHandler);
372
+ contents.style.animationName = animation;
373
+ this.animating = true;
374
+ });
375
+ }
376
+ renderTheme(content) {
377
+ const { color, scale, lang } = this.theme;
378
+ return html `
379
+ <sp-theme
380
+ color=${ifDefined(color)}
381
+ scale=${ifDefined(scale)}
382
+ lang=${ifDefined(lang)}
383
+ part="theme"
384
+ >
385
+ ${content}
386
+ </sp-theme>
387
+ `;
388
+ }
389
+ render() {
390
+ const content = html `
391
+ <div id="contents">
392
+ <slot @slotchange=${this.onSlotChange}></slot>
393
+ </div>
394
+ `;
395
+ return this.hasTheme ? this.renderTheme(content) : content;
396
+ }
397
+ static create(details) {
398
+ const overlay = new ActiveOverlay();
399
+ if (details.content) {
400
+ overlay.open(details);
401
+ }
402
+ return overlay;
403
+ }
404
+ async getUpdateComplete() {
405
+ const actions = [
406
+ super.getUpdateComplete(),
407
+ this.stealOverlayContentPromise,
408
+ ];
409
+ if (this.childrenReady) {
410
+ actions.push(this.childrenReady);
411
+ }
412
+ const [complete] = await Promise.all(actions);
413
+ return complete;
414
+ }
415
+ disconnectedCallback() {
416
+ document.removeEventListener('sp-update-overlays', this.updateOverlayPosition);
417
+ window.removeEventListener('scroll', this.updateOverlayPosition);
418
+ super.disconnectedCallback();
419
+ }
420
+ }
421
+ __decorate([
422
+ property()
423
+ ], ActiveOverlay.prototype, "_state", void 0);
424
+ __decorate([
425
+ property({ reflect: true, type: Boolean })
426
+ ], ActiveOverlay.prototype, "animating", void 0);
427
+ __decorate([
428
+ property({ reflect: true })
429
+ ], ActiveOverlay.prototype, "placement", void 0);
430
+ __decorate([
431
+ property({ attribute: false })
432
+ ], ActiveOverlay.prototype, "theme", void 0);
433
+ __decorate([
434
+ property({ attribute: false })
435
+ ], ActiveOverlay.prototype, "receivesFocus", void 0);
436
+ //# sourceMappingURL=ActiveOverlay.js.map