<commit_before>import { Component, OnInit, ViewChild, Output, EventEmitter, AfterViewInit, Input, OnDestroy } from '@angular/core';

@Component({
    selector: 'app-modal-resizable',
    templateUrl: './modal-resizable.component.html',
    styleUrls: ['./modal-resizable.component.css']
})
export class ModalResizableComponent implements OnInit, AfterViewInit, OnDestroy {
    static ZIndex = 12;
    _content;

    @ViewChild('layerZIndex', {static: false}) layerZIndex;
    @ViewChild('containerWindow', {static: false}) containerWindow;
    @ViewChild('inWindow', {static: false}) inWindow;
    @ViewChild('outWindow', {static: false}) outWindow;

    @Input() title: string;
    @Input() headerColor: string;
    @Input() width = 700;
    @Input() height = 600;
    @Input() minWidth = 300;
    @Input() minHeight = 300;
    @Input() mouseEventData = null;
    @Input() isBrowserWindow = false;
    @Input() startZIndex: number = 0;
    __isBrowserWindow = false;
    @Output() close: EventEmitter<any> = new EventEmitter();
    @Output() browserWindow: EventEmitter<any> = new EventEmitter();
    isFullPage = false;

    constructor() { }

    ngOnInit() { }

    onFullPage () {
        this.isFullPage = !this.isFullPage;
    }

    ngAfterViewInit() {
        /* attache window to native document.body */
        document.body.appendChild(this.layerZIndex.nativeElement);

        /* clculation max windows size */
        const maxWidth = window.innerWidth * 0.95;
        const maxHeight = window.innerHeight * 0.8;
        this.minWidth = Math.min(this.minWidth, maxWidth);
        this.minHeight = Math.min(this.minWidth, maxHeight);
        (s => {
            s.minWidth = Math.min(maxWidth, Math.max(this.minWidth, this.width)) + 'px';
            s.minHeight = Math.min(maxHeight, Math.max(this.minHeight, this.height)) + 'px';
            s.width = Math.min(this.width, maxWidth) + 'px';
            s.height = Math.min(this.height, maxHeight) + 'px';
        })(this.containerWindow.nativeElement.style);

        if (this.mouseEventData) {
            this.setPositionWindow(this.mouseEventData.clientX, this.mouseEventData.clientY);
        }
        this.onFocus();
        if (this.isBrowserWindow) {
            this.newWindow();
        }
    }
    setPositionWindow(x = 0, y = 0) {
        const el = this.containerWindow.nativeElement;
        const positionLocal = this.getTranslatePosition(el);
        const positionGlobal = el.getBoundingClientRect();
        x = Math.min(window.innerWidth - positionGlobal.width, x);
        y = Math.min(window.innerHeight - positionGlobal.height, y);
        positionLocal.x -= positionGlobal.left;
        positionLocal.y -= positionGlobal.top;
        positionLocal.x = Math.round(positionLocal.x + x);
        positionLocal.y = Math.round(positionLocal.y + y);

        el.style.transform = `translate3d(${positionLocal.x}px, ${positionLocal.y}px, 0px)`;
    }
    onClose () {
        this.close.emit();
    }

    onFocus () {
        this.layerZIndex.nativeElement.style.zIndex = '' + ((ModalResizableComponent.ZIndex += 2) + this.startZIndex);
    }
<commit_msg>fix: https://github.com/sipcapture/homer-app/issues/257 New window popup position<commit_after>import { Component, OnInit, ViewChild, Output, EventEmitter, AfterViewInit, Input, OnDestroy } from '@angular/core';

@Component({
    selector: 'app-modal-resizable',
    templateUrl: './modal-resizable.component.html',
    styleUrls: ['./modal-resizable.component.css']
})
export class ModalResizableComponent implements OnInit, AfterViewInit, OnDestroy {
    static ZIndex = 12;
    _content;

    @ViewChild('layerZIndex', {static: false}) layerZIndex;
    @ViewChild('containerWindow', {static: false}) containerWindow;
    @ViewChild('inWindow', {static: false}) inWindow;
    @ViewChild('outWindow', {static: false}) outWindow;

    @Input() title: string;
    @Input() headerColor: string;
    @Input() width = 700;
    @Input() height = 600;
    @Input() minWidth = 300;
    @Input() minHeight = 300;
    @Input() mouseEventData = null;
    @Input() isBrowserWindow = false;
    @Input() startZIndex: number = 0;
    __isBrowserWindow = false;
    @Output() close: EventEmitter<any> = new EventEmitter();
    @Output() browserWindow: EventEmitter<any> = new EventEmitter();
    isFullPage = false;

    constructor() { }

    ngOnInit() { }

    onFullPage () {
        this.isFullPage = !this.isFullPage;
    }

    ngAfterViewInit() {
        /* attache window to native document.body */
        document.body.appendChild(this.layerZIndex.nativeElement);

        /* clculation max windows size */
        const maxWidth = window.innerWidth * 0.95;
        const maxHeight = window.innerHeight * 0.8;
        this.minWidth = Math.min(this.minWidth, maxWidth);
        this.minHeight = Math.min(this.minWidth, maxHeight);
        (s => {
            s.minWidth = Math.min(maxWidth, Math.max(this.minWidth, this.width)) + 'px';
            s.minHeight = Math.min(maxHeight, Math.max(this.minHeight, this.height)) + 'px';
            s.width = Math.min(this.width, maxWidth) + 'px';
            s.height = Math.min(this.height, maxHeight) + 'px';
        })(this.containerWindow.nativeElement.style);

        if (this.mouseEventData) {
            const mouseOffset = 50; // 50px inside window
            this.setPositionWindow({
                x: this.mouseEventData.clientX - mouseOffset,
                y: this.mouseEventData.clientY - mouseOffset
            });
        }
        this.onFocus();
        if (this.isBrowserWindow) {
            this.newWindow();
        }
    }
    setPositionWindow({x = 0, y = 0}) {
        const el = this.containerWindow.nativeElement;
        const positionLocal = this.getTranslatePosition(el);
        const positionGlobal = el.getBoundingClientRect();
        x = Math.min(window.innerWidth - positionGlobal.width, x);
        y = Math.min(window.innerHeight - positionGlobal.height, y);
        positionLocal.x -= positionGlobal.left;
        positionLocal.y -= positionGlobal.top;
        positionLocal.x = Math.round(positionLocal.x + x);
        positionLocal.y = Math.round(positionLocal.y + y);

        el.style.transform = `translate3d(${positionLocal.x}px, ${positionLocal.y}px, 0px)`;
    }
    onClose () {
        this.close.emit();
    }

    onFocus () {
        this.layerZIndex.nativeElement.style.zIndex = '' + ((ModalResizableComponent.ZIndex += 2) + this.startZIndex);
    }

{'fraction_non_alphanumeric': 0.13695249845774213, 'fraction_numerical': 0.00879086983343615, 'mean_word_length': 2.8418246445497632, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3871512', 'n_tokens_mistral': 2008, 'n_tokens_neox': 1942, 'n_words': 390}