var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { CSSType, PercentLength, View, Utils, Property, booleanConverter, Screen } from '@nativescript/core';
const defaultGLOptions = {
    alpha: true,
    antialias: true,
    depth: true,
    failIfMajorPerformanceCaveat: false,
    powerPreference: 'default',
    premultipliedAlpha: true,
    preserveDrawingBuffer: false,
    stencil: false,
    desynchronized: false,
    xrCompatible: false
};
const default2DOptions = {
    alpha: true,
    antialias: true,
    depth: true,
    failIfMajorPerformanceCaveat: false,
    powerPreference: 'default',
    premultipliedAlpha: true,
    preserveDrawingBuffer: false,
    stencil: false,
    desynchronized: false,
    xrCompatible: false
};
export class DOMRectReadOnly {
    constructor(x, y, width, height, top, right, bottom, left) {
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
        this.left = left ?? x;
        this.top = top ?? y;
        this.right = right ?? x + width;
        this.bottom = bottom ?? y + height;
    }
}
export class DOMRect extends DOMRectReadOnly {
    constructor(x, y, width, height, top, right, bottom, left) {
        super(x, y, width, height, top, right, bottom, left);
    }
}
export class Event {
    constructor(type, options) {
        this.bubbles = false;
        this.cancelable = false;
        this.composed = false;
        this.type = type;
        this.bubbles = options?.bubbles ?? false;
        this.cancelable = options?.cancelable ?? false;
        this.cancelable = options?.cancelable ?? false;
        this.composed = options?.composed ?? false;
    }
    preventDefault() {
    }
    stopPropagation() {
    }
}
export class UIEvent extends Event {
    constructor(type, options) {
        super(type, options);
        this.detail = options?.detail ?? 0;
        this.view = options?.view ?? null;
        this.sourceCapabilities = options.sourceCapabilities ?? {};
    }
}
export class MouseEvent extends UIEvent {
    constructor(type, options) {
        super(type, options);
        this.screenX = options?.screenX ?? 0;
        this.screenY = options?.screenY ?? 0;
        this.clientX = options?.clientX ?? 0;
        this.clientY = options?.clientY ?? 0;
        this.ctrlKey = options?.ctrlKey ?? false;
        this.shiftKey = options?.ctrlKey ?? false;
        this.altKey = options?.ctrlKey ?? false;
        this.metaKey = options?.ctrlKey ?? false;
        this.button = options?.button ?? 0;
        this.buttons = options?.buttons ?? 0;
        this.relatedTarget = options?.relatedTarget ?? null;
        this.region = options?.region ?? null;
        this.movementX = options?.movementX ?? 0;
        this.movementY = options?.movementY ?? 0;
        this.pageX = options?.pageX ?? 0;
        this.pageY = options?.pageY ?? 0;
    }
}
export class PointerEvent extends MouseEvent {
    constructor(type, options) {
        super(type, options);
        this.pointerType = options?.pointerType ?? '';
        this.type = type;
        this.pointerId = options?.pointerId ?? 0;
        this.width = options?.width ?? 1;
        this.height = options?.height ?? 1;
        this.pressure = options?.pressure ?? 0;
        this.tangentialPressure = options?.tangentialPressure ?? 0;
        this.tiltX = options?.tiltX ?? 0;
        this.tiltY = options?.tiltY ?? 0;
        this.twist = options?.twist ?? 0;
        this.isPrimary = options?.isPrimary ?? false;
    }
    preventDefault() {
    }
    stopPropagation() {
    }
}
export class Touch {
    constructor(options) {
        this.identifier = options.identifier;
        this.target = options.target;
        this.clientX = options?.clientX ?? 0;
        this.clientY = options?.clientY ?? 0;
        this.screenX = options?.screenX ?? 0;
        this.screenY = options?.screenY ?? 0;
        this.pageX = options?.pageX ?? 0;
        this.pageY = options?.pageY ?? 0;
        this.radiusX = options?.radiusX ?? 0;
        this.radiusY = options?.radiusY ?? 0;
        this.rotationAngle = options?.rotationAngle ?? 0;
        this.force = options?.force ?? 0;
    }
    preventDefault() {
    }
    stopPropagation() {
    }
}
export class TouchList {
    static fromList(list) {
        const ret = new TouchList();
        ret._list = list;
        return ret;
    }
    static empty() {
        const ret = new TouchList();
        ret._list = [];
        return ret;
    }
    item(index) {
        return this._list[index];
    }
    get length() {
        return this._list.length;
    }
}
export class TouchEvent extends UIEvent {
    constructor(type, options) {
        super(type, options);
        this.touches = options?.touches ?? TouchList.empty();
        this.targetTouches = options?.touches ?? TouchList.empty();
        this.changedTouches = options?.changedTouches ?? [];
        this.altKey = options?.altKey ?? false;
        this.metaKey = options?.metaKey ?? false;
        this.ctrlKey = options?.ctrlKey ?? false;
        this.shiftKey = options?.shiftKey ?? false;
    }
    preventDefault() {
    }
    stopPropagation() {
    }
}
export class WheelEvent extends UIEvent {
    constructor(type, options) {
        super('wheel', options);
        this.deltaX = options?.deltaX ?? 0;
        this.deltaY = options?.deltaY ?? 0;
        this.deltaZ = options?.deltaZ ?? 0;
        this.deltaMode = options?.deltaMode ?? 0;
    }
}
class Rectangle {
    constructor(top, left, width, height) {
        this.top = top;
        this.left = left;
        // check name of fields!
        this.width = width;
        this.height = height;
    }
}
export const ignoreTouchEventsProperty = new Property({
    name: 'ignoreTouchEvents',
    defaultValue: false,
    valueConverter: booleanConverter
});
export const doc = {
    defaultView: {
        getComputedStyle: function () {
            return null;
        }
    }
};
let CanvasBase = class CanvasBase extends View {
    constructor() {
        super();
        this._isCustom = false;
        this._pointerMoveCallbacks = [];
        this._pointerUpCallbacks = [];
        this._pointerOutCallbacks = [];
        this._pointerLeaveCallbacks = [];
        this._pointerDownCallbacks = [];
        this._pointerCancelCallbacks = [];
        // For mouse compat because wtf
        this._mouseMoveCallbacks = [];
        this._mouseUpCallbacks = [];
        this._mouseDownCallbacks = [];
        this._mouseCancelCallbacks = [];
        this._mouseWheelCallbacks = [];
        this._touchStartCallbacks = new Array();
        this._touchEndCallbacks = new Array();
        this._touchMoveCallbacks = new Array();
        this._touchCancelCallbacks = new Array();
        this._touches = [];
        this._touchesById = [];
        this._lastPointerEventById = [];
        this._classList = new Set();
    }
    get ownerDocument() {
        return window?.document ?? doc;
    }
    addEventListener(arg, callback, thisArg) {
        super.addEventListener(arg, callback, thisArg);
        if (typeof arg !== 'string') {
            return;
        }
        const eventtype = arg.toLowerCase();
        switch (eventtype) {
            case 'mousemove':
                this._mouseMoveCallbacks.push(callback);
                break;
            case 'pointermove':
                this._pointerMoveCallbacks.push(callback);
                break;
            case 'mousedown':
                this._mouseDownCallbacks.push(callback);
                break;
            case 'pointerdown':
                this._pointerDownCallbacks.push(callback);
                break;
            case 'mouseup':
                this._mouseUpCallbacks.push(callback);
                break;
            case 'pointerup':
                this._pointerUpCallbacks.push(callback);
                break;
            case 'pointerout':
                this._pointerOutCallbacks.push(callback);
                break;
            case 'pointerleave':
                this._pointerLeaveCallbacks.push(callback);
                break;
            case 'mouseout':
            case 'mousecancel':
                this._mouseCancelCallbacks.push(callback);
                break;
            case 'pointercancel':
                this._pointerCancelCallbacks.push(callback);
                break;
            case 'touchstart':
                this._touchStartCallbacks.push(callback);
                break;
            case 'touchend':
                this._touchEndCallbacks.push(callback);
                break;
            case 'touchmove':
                this._touchMoveCallbacks.push(callback);
                break;
            case 'touchcancel':
                this._touchCancelCallbacks.push(callback);
                break;
            case 'wheel':
            case 'mousewheel':
            case 'dommousescroll':
                this._mouseWheelCallbacks.push(callback);
                break;
        }
    }
    _removeItemFromArray(array, item) {
        const index = array.indexOf(item);
        if (index !== -1) {
            array.splice(index, 1);
        }
    }
    removeEventListener(arg, callback, thisArg) {
        super.removeEventListener(arg, callback, thisArg);
        const eventtype = arg.toLowerCase();
        switch (eventtype) {
            case 'mousemove':
                this._removeItemFromArray(this._mouseMoveCallbacks, callback);
                break;
            case 'pointermove':
                this._removeItemFromArray(this._pointerMoveCallbacks, callback);
                break;
            case 'mousedown':
                this._removeItemFromArray(this._mouseDownCallbacks, callback);
                break;
            case 'pointerdown':
                this._removeItemFromArray(this._pointerDownCallbacks, callback);
                break;
            case 'mouseup':
                this._removeItemFromArray(this._mouseUpCallbacks, callback);
                break;
            case 'pointerup':
                this._removeItemFromArray(this._pointerUpCallbacks, callback);
                break;
            case 'pointerout':
                this._removeItemFromArray(this._pointerOutCallbacks, callback);
                break;
            case 'pointerleave':
                this._removeItemFromArray(this._pointerLeaveCallbacks, callback);
                break;
            case 'mouseout':
            case 'mousecancel':
                this._removeItemFromArray(this._mouseCancelCallbacks, callback);
                break;
            case 'pointercancel':
                this._removeItemFromArray(this._pointerCancelCallbacks, callback);
                break;
            case 'touchstart':
                this._removeItemFromArray(this._touchStartCallbacks, callback);
                break;
            case 'touchend':
                this._removeItemFromArray(this._touchEndCallbacks, callback);
                break;
            case 'touchmove':
                this._removeItemFromArray(this._touchMoveCallbacks, callback);
                break;
            case 'touchcancel':
                this._removeItemFromArray(this._touchCancelCallbacks, callback);
                break;
            case 'wheel':
            case 'mousewheel':
            case 'dommousescroll':
                this._removeItemFromArray(this._mouseWheelCallbacks, callback);
                break;
        }
    }
    _moveCallback(pointers) {
        const hasPointerCallbacks = this._pointerMoveCallbacks.length > 0;
        const hasMouseCallbacks = this._mouseMoveCallbacks.length > 0;
        if (hasPointerCallbacks || hasMouseCallbacks) {
            for (const pointer of pointers) {
                const pointerId = pointer.ptrId;
                const index = this._lastPointerEventById.findIndex((item) => {
                    return item?.pointerId === pointerId;
                });
                let previousEvent;
                if (index > -1) {
                    previousEvent = this._lastPointerEventById[index];
                }
                else {
                    previousEvent = { pointerId, x: 0, y: 0 };
                }
                if (hasPointerCallbacks) {
                    const event = new PointerEvent('pointermove', {
                        pointerType: 'touch',
                        pointerId,
                        clientX: pointer.x,
                        clientY: pointer.y,
                        screenX: pointer.x,
                        screenY: pointer.y,
                        pageX: pointer.x,
                        pageY: pointer.y,
                        movementX: pointer.x - previousEvent.x,
                        movementY: pointer.y - previousEvent.y,
                        isPrimary: pointer.isPrimary,
                        button: -1
                    });
                    for (const callback of this._pointerMoveCallbacks) {
                        callback(event);
                    }
                }
                if (hasMouseCallbacks) {
                    const event = new MouseEvent('mousemove', {
                        clientX: pointer.x,
                        clientY: pointer.y,
                        screenX: pointer.x,
                        screenY: pointer.y,
                        pageX: pointer.x,
                        pageY: pointer.y,
                        movementX: pointer.x - previousEvent.x,
                        movementY: pointer.y - previousEvent.y,
                        button: -1
                    });
                    for (const callback of this._mouseMoveCallbacks) {
                        callback(event);
                    }
                }
                if (index > -1) {
                    this._lastPointerEventById[index] = { pointerId, x: pointer.x, y: pointer.y };
                }
            }
        }
        if (this._touchMoveCallbacks.length > 0) {
            const changedTouches = [];
            for (const pointer of pointers) {
                changedTouches.push(new Touch({
                    identifier: pointer.ptrId,
                    target: null,
                    clientX: pointer.x,
                    clientY: pointer.y,
                    screenX: pointer.x,
                    screenY: pointer.y,
                    pageX: pointer.x,
                    pageY: pointer.y
                }));
            }
            const touches = TouchList.fromList(this._touches);
            const event = new TouchEvent('touchmove', {
                touches,
                targetTouches: touches,
                changedTouches
            });
            for (const callback of this._touchMoveCallbacks) {
                callback(event);
            }
        }
    }
    _upCallback(ptrId, x, y, isPrimary = false) {
        const hasPointerCallbacks = this._pointerUpCallbacks.length > 0 || this._pointerOutCallbacks.length > 0 || this._pointerLeaveCallbacks.length > 0;
        const hasMouseCallbacks = this._mouseUpCallbacks.length > 0;
        if (hasPointerCallbacks || hasMouseCallbacks) {
            const pointerId = ptrId;
            if (hasPointerCallbacks) {
                const up = new PointerEvent('pointerup', {
                    pointerType: 'touch',
                    pointerId,
                    clientX: x,
                    clientY: y,
                    screenX: x,
                    screenY: y,
                    isPrimary,
                    pageX: x,
                    pageY: y
                });
                const out = new PointerEvent('pointerout', {
                    pointerType: 'touch',
                    pointerId,
                    clientX: x,
                    clientY: y,
                    screenX: x,
                    screenY: y,
                    isPrimary,
                    pageX: x,
                    pageY: y
                });
                const leave = new PointerEvent('pointerleave', {
                    pointerType: 'touch',
                    pointerId,
                    clientX: x,
                    clientY: y,
                    screenX: x,
                    screenY: y,
                    isPrimary,
                    pageX: x,
                    pageY: y
                });
                for (const callback of this._pointerUpCallbacks) {
                    callback(up);
                }
                for (const callback of this._pointerOutCallbacks) {
                    callback(out);
                }
                for (const callback of this._pointerLeaveCallbacks) {
                    callback(leave);
                }
            }
            if (hasMouseCallbacks) {
                const event = new MouseEvent('mouseup', {
                    clientX: x,
                    clientY: y,
                    screenX: x,
                    screenY: y,
                    pageX: x,
                    pageY: y
                });
                for (const callback of this._mouseUpCallbacks) {
                    callback(event);
                }
            }
            const index = this._lastPointerEventById.findIndex((item) => {
                return item?.pointerId === pointerId;
            });
            if (index > -1) {
                this._lastPointerEventById.splice(index, 1);
            }
        }
        const length = this._touches.length;
        for (let i = 0; i < length; i++) {
            if (this._touches[i].identifier == ptrId) {
                this._touches.splice(i, 1);
                break;
            }
        }
        if (this._touchEndCallbacks.length > 0) {
            const touches = TouchList.fromList(this._touches);
            const changedTouches = [
                new Touch({
                    identifier: ptrId,
                    target: null,
                    clientX: x,
                    clientY: y,
                    screenX: x,
                    screenY: y,
                    pageX: x,
                    pageY: y
                })
            ];
            const event = new TouchEvent('touchend', {
                touches,
                targetTouches: touches,
                changedTouches
            });
            for (const callback of this._touchEndCallbacks) {
                callback(event);
            }
        }
    }
    _downCallback(ptrId, x, y, isPrimary = false) {
        const hasPointerCallbacks = this._pointerDownCallbacks.length > 0;
        const hasMouseCallbacks = this._mouseDownCallbacks.length > 0;
        if (hasPointerCallbacks || hasMouseCallbacks) {
            const pointerId = ptrId;
            if (hasPointerCallbacks) {
                const event = new PointerEvent('pointerdown', {
                    pointerType: 'touch',
                    pointerId,
                    clientX: x,
                    clientY: y,
                    screenX: x,
                    screenY: y,
                    isPrimary,
                    pageX: x,
                    pageY: y
                });
                for (const callback of this._pointerDownCallbacks) {
                    callback(event);
                }
            }
            if (hasMouseCallbacks) {
                const event = new MouseEvent('mousedown', {
                    clientX: x,
                    clientY: y,
                    screenX: x,
                    screenY: y,
                    pageX: x,
                    pageY: y
                });
                for (const callback of this._mouseDownCallbacks) {
                    callback(event);
                }
            }
            this._lastPointerEventById.push({ pointerId, x, y });
        }
        if (this._touchStartCallbacks.length > 0) {
            const touch = new Touch({
                identifier: ptrId,
                target: this,
                clientX: x,
                clientY: y,
                screenX: x,
                screenY: y,
                pageX: x,
                pageY: y
            });
            this._touches.push(touch);
            this._touchesById[ptrId] = touch;
            const touches = TouchList.fromList(this._touches);
            const touchEvent = new TouchEvent('touchstart', {
                touches,
                targetTouches: touches,
                changedTouches: this._touches
            });
            for (const callback of this._touchStartCallbacks) {
                callback(touchEvent);
            }
        }
    }
    _cancelCallback(ptrId, x, y, isPrimary = false) {
        const hasPointerCallbacks = this._pointerCancelCallbacks.length > 0;
        const hasMouseCallbacks = this._mouseCancelCallbacks.length > 0;
        if (hasPointerCallbacks || hasMouseCallbacks) {
            const pointerId = ptrId;
            if (hasPointerCallbacks) {
                const event = new PointerEvent('pointercancel', {
                    pointerType: 'touch',
                    pointerId,
                    clientX: x,
                    clientY: y,
                    screenX: x,
                    screenY: y,
                    pageX: x,
                    pageY: y,
                    isPrimary
                });
                for (const callback of this._pointerCancelCallbacks) {
                    callback(event);
                }
            }
            if (hasMouseCallbacks) {
                const event = new MouseEvent('mouseout', {
                    clientX: x,
                    clientY: y,
                    screenX: x,
                    screenY: y,
                    pageX: x,
                    pageY: y
                });
                for (const callback of this._mouseCancelCallbacks) {
                    callback(event);
                }
            }
        }
        if (this._touchCancelCallbacks.length > 0) {
            const touch = new Touch({
                identifier: ptrId,
                target: this,
                clientX: x,
                clientY: y,
                screenX: x,
                screenY: y,
                pageX: x,
                pageY: y
            });
            const touchesList = [touch];
            const touchesById = [];
            touchesById[ptrId] = touch;
            const touches = TouchList.fromList(touchesList);
            const touchEvent = new TouchEvent('touchcancel', {
                touches,
                targetTouches: touches,
                changedTouches: touchesList
            });
            for (const callback of this._touchCancelCallbacks) {
                callback(touchEvent);
            }
        }
    }
    _pinchCallback(data) {
        // move callback
        const hasPointerCallbacks = this._pointerMoveCallbacks.length > 0;
        const hasMouseCallbacks = this._mouseMoveCallbacks.length > 0;
        const hasMouseWheel = this._mouseWheelCallbacks.length > 0;
        if (hasPointerCallbacks || hasMouseCallbacks || hasMouseWheel) {
            for (const pointer of data.pointers) {
                const pointerId = pointer.ptrId;
                const index = this._lastPointerEventById.findIndex((item) => {
                    return item?.pointerId === pointerId;
                });
                let previousEvent;
                if (index > -1) {
                    previousEvent = this._lastPointerEventById[index];
                }
                else {
                    previousEvent = { pointerId, x: 0, y: 0 };
                }
                if (hasPointerCallbacks) {
                    const event = new PointerEvent('pointermove', {
                        pointerType: 'touch',
                        pointerId,
                        clientX: pointer.x,
                        clientY: pointer.y,
                        screenX: pointer.x,
                        screenY: pointer.y,
                        pageX: pointer.x,
                        pageY: pointer.y,
                        movementX: pointer.x - previousEvent.x,
                        movementY: pointer.y - previousEvent.y,
                        button: -1
                    });
                    for (const callback of this._pointerMoveCallbacks) {
                        callback(event);
                    }
                }
                if (hasMouseCallbacks) {
                    const event = new MouseEvent('mousemove', {
                        clientX: pointer.x,
                        clientY: pointer.y,
                        screenX: pointer.x,
                        screenY: pointer.y,
                        pageX: pointer.x,
                        pageY: pointer.y,
                        movementX: pointer.x - previousEvent.x,
                        movementY: pointer.y - previousEvent.y,
                        button: -1
                    });
                    for (const callback of this._mouseMoveCallbacks) {
                        callback(event);
                    }
                }
                if (hasMouseWheel) {
                    const event = new WheelEvent('wheel', {
                        deltaX: data.deltaX,
                        deltaY: data.deltaY,
                        deltaZ: 0,
                        deltaMode: data.deltaMode
                    });
                    for (const callback of this._mouseWheelCallbacks) {
                        callback(event);
                    }
                }
                if (index > -1) {
                    this._lastPointerEventById[index] = { pointerId, x: pointer.x, y: pointer.y };
                }
            }
        }
        if (this._touchMoveCallbacks.length > 0) {
            const changedTouches = [];
            for (const pointer of data.pointers) {
                changedTouches.push(new Touch({
                    identifier: pointer.ptrId,
                    target: this,
                    clientX: pointer.x,
                    clientY: pointer.y,
                    screenX: pointer.x,
                    screenY: pointer.y,
                    pageX: pointer.x,
                    pageY: pointer.y
                }));
            }
            const touches = TouchList.fromList(this._touches);
            const event = new TouchEvent('touchmove', {
                touches,
                targetTouches: touches,
                changedTouches
            });
            for (const callback of this._touchMoveCallbacks) {
                callback(event);
            }
        }
    }
    _handleEvents(event) {
        try {
            const data = JSON.parse(event);
            switch (data.event) {
                case 'down':
                    this._downCallback(data.ptrId, data.x, data.y, data.isPrimary);
                    break;
                case 'move':
                    this._moveCallback(data.pointers);
                    break;
                case 'up':
                    this._upCallback(data.ptrId, data.x, data.y, data.isPrimary);
                    break;
                case 'scale':
                    this._pinchCallback(data);
                    break;
                case 'cancel':
                    this._cancelCallback(data.ptrId, data.x, data.y, data.isPrimary);
                    break;
                default:
                    break;
            }
        }
        catch (error) {
        }
    }
    get classList() {
        return this._classList;
    }
    get _physicalSize() {
        return {
            width: this.getSize(this.style.width, this.getMeasuredWidth(), 'physical'),
            height: this.getSize(this.style.height, this.getMeasuredHeight(), 'physical')
        };
    }
    get _logicalSize() {
        return {
            width: this.getSize(this.style.width, this.getMeasuredWidth()),
            height: this.getSize(this.style.height, this.getMeasuredHeight())
        };
    }
    _handlePowerPreference(powerPreference) {
        switch (powerPreference) {
            case 'default':
                return 0;
            case 'high-performance':
                return 1;
            case 'low-power':
                return 2;
            default:
                return -1;
        }
    }
    _handleContextOptions(type, contextOpts) {
        if (!contextOpts) {
            if (type === '2d') {
                return { ...default2DOptions, powerPreference: 0 };
            }
            if (type.indexOf('webgl') > -1) {
                return { ...defaultGLOptions, powerPreference: 0 };
            }
        }
        if (type === '2d') {
            if (contextOpts.alpha !== undefined && typeof contextOpts.alpha === 'boolean') {
                return { ...contextOpts, powerPreference: 0 };
            }
            else {
                return { alpha: true, powerPreference: 0 };
            }
        }
        const glOptions = { ...defaultGLOptions };
        const setIfDefined = (prop, value) => {
            const property = glOptions[prop];
            if (property !== undefined && prop === 'powerPreference') {
                // converts to int
                glOptions[prop] = value;
            }
            if (property !== undefined && typeof value === typeof property) {
                glOptions[prop] = value;
            }
        };
        if (type.indexOf('webgl') > -1 || type === 'experimental-webgl') {
            setIfDefined('alpha', contextOpts.alpha);
            setIfDefined('antialias', contextOpts.antialias);
            setIfDefined('depth', contextOpts.depth);
            setIfDefined('failIfMajorPerformanceCaveat', contextOpts.failIfMajorPerformanceCaveat);
            setIfDefined('powerPreference', this._handlePowerPreference(contextOpts.powerPreference ?? 'default'));
            setIfDefined('premultipliedAlpha', contextOpts.premultipliedAlpha);
            setIfDefined('preserveDrawingBuffer', contextOpts.preserveDrawingBuffer);
            setIfDefined('stencil', contextOpts.stencil);
            setIfDefined('desynchronized', contextOpts.desynchronized);
            return glOptions;
        }
        return null;
    }
    _readyEvent() {
        this.notify({
            eventName: 'ready',
            object: this
        });
    }
    getAttribute(attrib) {
        if (attrib === 'width') {
            return this.width;
        }
        if (attrib === 'height') {
            return this.height;
        }
        if (attrib === 'tabindex') {
            return (this['tabindex'] = arguments[1]);
        }
        return this[attrib];
    }
    setAttribute(attrib) {
        if (attrib === 'width') {
            if (!isNaN(parseInt(arguments[1]))) {
                this.width = parseInt(arguments[1]);
            }
        }
        if (attrib === 'height') {
            if (!isNaN(parseInt(arguments[1]))) {
                this.height = parseInt(arguments[1]);
            }
        }
        if (attrib === 'tabindex') {
            this['tabindex'] = arguments[1];
        }
    }
    getSize(value, measuredSize, type = 'logical') {
        const isPhysical = type === 'physical';
        if (value === undefined || value === null) {
            return 0;
        }
        if (value === 'auto') {
            const size = Utils.layout.getMeasureSpecSize(Utils.layout.makeMeasureSpec(measuredSize, Utils.layout.UNSPECIFIED));
            if (isPhysical) {
                return size;
            }
            return Utils.layout.toDeviceIndependentPixels(size);
        }
        if (typeof value === 'string') {
            value = PercentLength.parse(value);
        }
        switch (typeof value) {
            case 'number': {
                if (isPhysical) {
                    return (value || 0) * Screen.mainScreen.scale;
                }
                return value || 0;
            }
            case 'object': {
                if (value.unit === 'dip' || value.unit === 'px') {
                    if (isPhysical) {
                        return (value.value || 0) * Screen.mainScreen.scale;
                    }
                    return value.value || 0;
                }
                else if (value.unit === '%') {
                    if (isPhysical) {
                        return measuredSize * value.value ?? 0;
                    }
                    return (measuredSize * value.value ?? 0) / Screen.mainScreen.scale;
                }
                return 0;
            }
            default:
                return 0;
        }
    }
    setPointerCapture(id) {
    }
    releasePointerCapture(id) {
    }
};
CanvasBase.readyEvent = 'ready';
CanvasBase = __decorate([
    CSSType('Canvas'),
    __metadata("design:paramtypes", [])
], CanvasBase);
export { CanvasBase };
//# sourceMappingURL=common.js.map