| 
									
										
										
										
											2023-12-08 19:16:22 +01:00
										 |  |  | import { customElement, DeesElement, domtools, type TemplateResult, html, property, type CSSResult, state, } from '@design.estate/dees-element'; | 
					
						
							| 
									
										
										
										
											2025-06-26 18:37:49 +00:00
										 |  |  | import { zIndexLayers, zIndexRegistry } from './00zindex.js'; | 
					
						
							| 
									
										
										
										
											2021-02-13 21:52:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | declare global { | 
					
						
							|  |  |  |   interface HTMLElementTagNameMap { | 
					
						
							|  |  |  |     'dees-windowlayer': DeesWindowLayer; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-13 16:46:00 +02:00
										 |  |  | export interface IOptions_DeesWindowLayer { | 
					
						
							|  |  |  |   blur: boolean; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-13 21:52:36 +00:00
										 |  |  | @customElement('dees-windowlayer') | 
					
						
							| 
									
										
										
										
											2022-01-24 01:39:47 +01:00
										 |  |  | export class DeesWindowLayer extends DeesElement { | 
					
						
							| 
									
										
										
										
											2021-09-01 21:48:22 +02:00
										 |  |  |   // STATIC
 | 
					
						
							| 
									
										
										
										
											2021-02-13 21:52:36 +00:00
										 |  |  |   public static demo = () => html`<dees-windowlayer></dees-windowlayer>`; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-13 16:46:00 +02:00
										 |  |  |   public static async createAndShow(optionsArg?: IOptions_DeesWindowLayer) { | 
					
						
							| 
									
										
										
										
											2023-09-04 19:28:50 +02:00
										 |  |  |     const domtoolsInstance = domtools.DomTools.getGlobalDomToolsSync(); | 
					
						
							|  |  |  |     const windowLayer = new DeesWindowLayer(); | 
					
						
							| 
									
										
										
										
											2023-09-13 16:46:00 +02:00
										 |  |  |     windowLayer.options = { | 
					
						
							|  |  |  |       ...windowLayer.options, | 
					
						
							|  |  |  |       ...optionsArg, | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-09-04 19:28:50 +02:00
										 |  |  |     document.body.append(windowLayer); | 
					
						
							|  |  |  |     await domtoolsInstance.convenience.smartdelay.delayFor(0); | 
					
						
							|  |  |  |     windowLayer.show(); | 
					
						
							|  |  |  |     return windowLayer; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-13 16:46:00 +02:00
										 |  |  |   @state() | 
					
						
							|  |  |  |   public options: IOptions_DeesWindowLayer = { | 
					
						
							|  |  |  |     blur: false | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2025-06-26 18:37:49 +00:00
										 |  |  |    | 
					
						
							|  |  |  |   @state() | 
					
						
							|  |  |  |   private backdropZIndex: number = 1000; | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   @state() | 
					
						
							|  |  |  |   private contentZIndex: number = 1001; | 
					
						
							| 
									
										
										
										
											2023-09-13 16:46:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-01 21:48:22 +02:00
										 |  |  |   // INSTANCE
 | 
					
						
							|  |  |  |   @property({ | 
					
						
							|  |  |  |     type: Boolean | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  |   public visible = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-13 21:52:36 +00:00
										 |  |  |   constructor() { | 
					
						
							|  |  |  |     super(); | 
					
						
							|  |  |  |     domtools.elementBasic.setup(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public render(): TemplateResult { | 
					
						
							|  |  |  |     return html`
 | 
					
						
							|  |  |  |       ${domtools.elementBasic.styles} | 
					
						
							|  |  |  |       <style> | 
					
						
							|  |  |  |         .windowOverlay { | 
					
						
							| 
									
										
										
										
											2023-09-04 19:28:50 +02:00
										 |  |  |           transition: all 0.2s; | 
					
						
							| 
									
										
										
										
											2021-08-29 17:10:25 +02:00
										 |  |  |           will-change: transform; | 
					
						
							| 
									
										
										
										
											2021-02-13 21:52:36 +00:00
										 |  |  |           position: fixed; | 
					
						
							|  |  |  |           top: 0px; | 
					
						
							|  |  |  |           left: 0px; | 
					
						
							|  |  |  |           height: 100vh; | 
					
						
							|  |  |  |           width: 100vw; | 
					
						
							| 
									
										
										
										
											2021-08-29 17:10:25 +02:00
										 |  |  |           display: flex; | 
					
						
							|  |  |  |           justify-content: center; | 
					
						
							|  |  |  |           align-items: center; | 
					
						
							| 
									
										
										
										
											2021-02-13 21:52:36 +00:00
										 |  |  |           background: rgba(0, 0, 0, 0.0); | 
					
						
							| 
									
										
										
										
											2023-09-13 16:46:00 +02:00
										 |  |  |           backdrop-filter: brightness(1) ${this.options.blur ? 'blur(0px)' : ''}; | 
					
						
							| 
									
										
										
										
											2021-09-01 21:48:22 +02:00
										 |  |  |           pointer-events: none; | 
					
						
							| 
									
										
										
										
											2025-06-26 18:37:49 +00:00
										 |  |  |           z-index: ${this.backdropZIndex}; | 
					
						
							| 
									
										
										
										
											2021-02-13 21:52:36 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-11-29 17:20:32 +01:00
										 |  |  |         .slotContent { | 
					
						
							| 
									
										
										
										
											2023-11-29 20:39:17 +01:00
										 |  |  |           position: fixed; | 
					
						
							| 
									
										
										
										
											2023-11-29 17:20:32 +01:00
										 |  |  |           height: 100vh; | 
					
						
							|  |  |  |           width: 100vw; | 
					
						
							|  |  |  |           display: flex; | 
					
						
							|  |  |  |           justify-content: center; | 
					
						
							|  |  |  |           align-items: center; | 
					
						
							| 
									
										
										
										
											2025-06-26 18:37:49 +00:00
										 |  |  |           z-index: ${this.contentZIndex}; | 
					
						
							| 
									
										
										
										
											2025-06-26 23:19:43 +00:00
										 |  |  |           pointer-events: none; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |         .slotContent > * { | 
					
						
							|  |  |  |           pointer-events: auto; | 
					
						
							| 
									
										
										
										
											2023-11-29 17:20:32 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-08-29 17:10:25 +02:00
										 |  |  |          | 
					
						
							| 
									
										
										
										
											2021-02-13 21:52:36 +00:00
										 |  |  |         .visible { | 
					
						
							|  |  |  |           background: rgba(0, 0, 0, 0.2); | 
					
						
							| 
									
										
										
										
											2023-09-13 16:46:00 +02:00
										 |  |  |           backdrop-filter: brightness(0.9) ${this.options.blur ? 'blur(2px)' : ''}; | 
					
						
							| 
									
										
										
										
											2023-12-08 18:22:18 +01:00
										 |  |  |           pointer-events: all; | 
					
						
							| 
									
										
										
										
											2021-02-13 21:52:36 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |       </style> | 
					
						
							| 
									
										
										
										
											2025-06-26 20:20:34 +00:00
										 |  |  |       <div @click=${this.dispatchClicked} class="windowOverlay ${this.visible ? 'visible' : null}"> | 
					
						
							| 
									
										
										
										
											2023-11-29 17:20:32 +01:00
										 |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2025-06-26 20:20:34 +00:00
										 |  |  |       <div class="slotContent"> | 
					
						
							| 
									
										
										
										
											2021-02-13 21:52:36 +00:00
										 |  |  |         <slot></slot> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |     `;
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   firstUpdated() { | 
					
						
							|  |  |  |     setTimeout(() => { | 
					
						
							| 
									
										
										
										
											2021-09-01 21:48:22 +02:00
										 |  |  |       this.visible = true; | 
					
						
							| 
									
										
										
										
											2021-02-13 21:52:36 +00:00
										 |  |  |     }, 100); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-09-01 21:48:22 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   dispatchClicked() { | 
					
						
							| 
									
										
										
										
											2022-08-17 18:49:33 +02:00
										 |  |  |     this.dispatchEvent(new CustomEvent('clicked')); | 
					
						
							| 
									
										
										
										
											2021-09-01 21:48:22 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public toggleVisibility () { | 
					
						
							|  |  |  |     this.visible = !this.visible; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-06-26 18:37:49 +00:00
										 |  |  |    | 
					
						
							|  |  |  |   public getContentZIndex(): number { | 
					
						
							|  |  |  |     return this.contentZIndex; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-08-17 18:49:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   public async show() { | 
					
						
							|  |  |  |     const domtools = await this.domtoolsPromise; | 
					
						
							| 
									
										
										
										
											2025-06-26 18:37:49 +00:00
										 |  |  |      | 
					
						
							|  |  |  |     // Get z-indexes from registry
 | 
					
						
							|  |  |  |     this.backdropZIndex = zIndexRegistry.getNextZIndex(); | 
					
						
							|  |  |  |     this.contentZIndex = zIndexRegistry.getNextZIndex(); | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     // Register this element
 | 
					
						
							|  |  |  |     zIndexRegistry.register(this, this.backdropZIndex); | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2022-08-17 18:49:33 +02:00
										 |  |  |     await domtools.convenience.smartdelay.delayFor(0); | 
					
						
							|  |  |  |     this.visible = true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public async hide() { | 
					
						
							|  |  |  |     const domtools = await this.domtoolsPromise; | 
					
						
							|  |  |  |     await domtools.convenience.smartdelay.delayFor(0); | 
					
						
							|  |  |  |     this.visible = false; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-09-04 19:28:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   public async destroy() { | 
					
						
							|  |  |  |     const domtools = await this.domtoolsPromise; | 
					
						
							|  |  |  |     await this.hide(); | 
					
						
							|  |  |  |     await domtools.convenience.smartdelay.delayFor(300); | 
					
						
							| 
									
										
										
										
											2025-06-26 18:37:49 +00:00
										 |  |  |      | 
					
						
							|  |  |  |     // Unregister from z-index registry
 | 
					
						
							|  |  |  |     zIndexRegistry.unregister(this); | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2023-09-04 19:28:50 +02:00
										 |  |  |     this.remove(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-02-13 21:52:36 +00:00
										 |  |  | } |