{"version":3,"file":"angular-popout-window.mjs","sources":["../../../projects/popout-window/src/lib/popout-window.component.ts","../../../projects/popout-window/src/lib/popout-window.module.ts","../../../projects/popout-window/src/src.ts","../../../projects/popout-window/src/angular-popout-window.ts"],"sourcesContent":["import {\r\n  Component,\r\n  ElementRef,\r\n  HostListener,\r\n  Input, EventEmitter, OnDestroy, Output, Renderer2,\r\n  ViewChild\r\n} from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'popout-window',\r\n  template: `\r\n    <div #innerWrapper style=\"width: 100%; height: 100%; overflow: auto;\">\r\n      <ng-content></ng-content>\r\n    </div>\r\n  `\r\n})\r\n\r\nexport class PopoutWindowComponent implements OnDestroy  {\r\n\r\n  @ViewChild('innerWrapper') private innerWrapper: ElementRef;\r\n\r\n  @Input() windowWidth: number;\r\n  @Input() windowHeight: number;\r\n  @Input() windowLeft: number;\r\n  @Input() windowTop: number;\r\n  @Input() windowTitle: string;\r\n  @Input() windowStyle: string;\r\n  @Input() windowStyleUrl: string;\r\n  @Input() suppressCloneStyles = false;\r\n  @Input() get isPoppedOut(): boolean {\r\n    return this.isOut;\r\n  }\r\n  @Output() closed: EventEmitter<boolean> = new EventEmitter();\r\n\r\n  private popoutWindow: Window;\r\n  private isOut = false;\r\n  private observer: MutationObserver;\r\n\r\n  @HostListener('window:beforeunload')\r\n  private beforeunloadHandler(): void {\r\n    this.close();\r\n  }\r\n\r\n  constructor(\r\n    private renderer2: Renderer2,\r\n    private elementRef: ElementRef\r\n  ) {}\r\n\r\n  ngOnDestroy(): void {\r\n    this.observer?.disconnect();\r\n    this.close();\r\n  }\r\n\r\n  private close(): void {\r\n    if (this.popoutWindow) {\r\n      this.popoutWindow.close();\r\n      this.popoutWindow = null;\r\n      this.isOut = false;\r\n      this.closed.next(true);\r\n    }\r\n  }\r\n\r\n  public popIn(): void {\r\n    this.renderer2.appendChild(this.elementRef.nativeElement, this.innerWrapper.nativeElement);\r\n    this.close();\r\n  }\r\n\r\n  public popOut(): void {\r\n    if (!this.popoutWindow) {\r\n      const elmRect = this.innerWrapper.nativeElement.getBoundingClientRect();\r\n\r\n      const navHeight = window.outerHeight - window.innerHeight;\r\n      const navWidth = window.outerWidth - window.innerWidth;\r\n\r\n      const winLeft = this.windowLeft || window.screenX + navWidth + elmRect.left;\r\n      const winTop = this.windowTop || window.screenY + navHeight + elmRect.top - 60;\r\n\r\n      this.popoutWindow = window.open(\r\n        '',\r\n        `popoutWindow${Date.now()}`,\r\n        `width=${this.windowWidth > 99 ? this.windowWidth : elmRect.width},\r\n        height=${this.windowHeight > 99 ? this.windowHeight : elmRect.height + 1},\r\n        left=${winLeft},\r\n        top=${winTop}`\r\n      );\r\n\r\n      this.popoutWindow.document.title = this.windowTitle ? this.windowTitle : window.document.title;\r\n      this.popoutWindow.document.body.style.margin = '0';\r\n\r\n      if (!this.suppressCloneStyles) {\r\n        document.head.querySelectorAll('style').forEach(node => {\r\n          this.popoutWindow.document.head.appendChild(node.cloneNode(true));\r\n        });\r\n\r\n        this.observeStyleChanges();\r\n\r\n        document.head.querySelectorAll('link[rel=\"stylesheet\"]').forEach(node => {\r\n          this.popoutWindow.document.head.insertAdjacentHTML('beforeend',\r\n            `<link rel=\"stylesheet\" type=\"${(node as HTMLLinkElement).type}\" href=\"${(node as HTMLLinkElement).href}\">`);\r\n        });\r\n\r\n        (document as any).fonts.forEach(node => {\r\n          (this.popoutWindow.document as any).fonts.add(node);\r\n        });\r\n      }\r\n\r\n      if (this.windowStyleUrl) {\r\n        this.popoutWindow.document.head.insertAdjacentHTML('beforeend',\r\n          `<link rel=\"stylesheet\" type=\"text/css\" href=\"${window.location.origin}/${this.windowStyleUrl}\">`);\r\n      }\r\n\r\n      if (this.windowStyle) {\r\n        this.popoutWindow.document.head.insertAdjacentHTML('beforeend', `<style>${this.windowStyle}</style>`);\r\n      }\r\n\r\n      this.renderer2.appendChild(this.popoutWindow.document.body, this.innerWrapper.nativeElement);\r\n      this.isOut = true;\r\n\r\n      this.popoutWindow.addEventListener('unload', () => {\r\n        this.popIn();\r\n      });\r\n    } else {\r\n      this.popoutWindow.focus();\r\n    }\r\n  }\r\n\r\n  private observeStyleChanges(): void {\r\n    const docHead = document.querySelector('head');\r\n\r\n    this.observer?.disconnect();\r\n    this.observer = new MutationObserver((mutations: MutationRecord[]) => {\r\n      mutations.forEach((mutation: MutationRecord) => {\r\n        mutation.addedNodes.forEach((node: Node) => {\r\n          if (node.nodeName === 'STYLE') {\r\n            this.popoutWindow.document.head.appendChild(node.cloneNode(true));\r\n          }\r\n        });\r\n      });\r\n    });\r\n\r\n    this.observer.observe(docHead, { childList: true });\r\n  }\r\n}\r\n","import { NgModule } from '@angular/core';\r\nimport { PopoutWindowComponent } from './popout-window.component';\r\n\r\n@NgModule({\r\n  declarations: [PopoutWindowComponent],\r\n  exports: [PopoutWindowComponent]\r\n})\r\nexport class PopoutWindowModule { }\r\n","/*\r\n * Public API Surface of popout-window\r\n */\r\n\r\nexport * from './lib/popout-window.component';\r\nexport * from './lib/popout-window.module';\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './src';\n"],"names":[],"mappings":";;;MAiBa,qBAAqB,CAAA;IA0BhC,WACU,CAAA,SAAoB,EACpB,UAAsB,EAAA;QADtB,IAAS,CAAA,SAAA,GAAT,SAAS,CAAW;QACpB,IAAU,CAAA,UAAA,GAAV,UAAU,CAAY;QAjBvB,IAAmB,CAAA,mBAAA,GAAG,KAAK,CAAC;AAI3B,QAAA,IAAA,CAAA,MAAM,GAA0B,IAAI,YAAY,EAAE,CAAC;QAGrD,IAAK,CAAA,KAAA,GAAG,KAAK,CAAC;KAWlB;AAjBJ,IAAA,IAAa,WAAW,GAAA;QACtB,OAAO,IAAI,CAAC,KAAK,CAAC;KACnB;IAQO,mBAAmB,GAAA;QACzB,IAAI,CAAC,KAAK,EAAE,CAAC;KACd;IAOD,WAAW,GAAA;AACT,QAAA,IAAI,CAAC,QAAQ,EAAE,UAAU,EAAE,CAAC;QAC5B,IAAI,CAAC,KA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