๐Ÿ‘”MouseEvent+ext

browser โŸฉ event โŸฉ type โŸฉ mouse โŸฉ +ext

extend MouseEvent.

// ๐Ÿ”ธ .pointInViewport
// ๐Ÿ”ธ .pointInPage
// ๐Ÿ”ธ .pointInScreen
// ๐Ÿ”น .pointInElement()

๐Ÿ‘‰ custom

// 2023.01.21 - 12:20 (โ€ข) first draft
// -------------------------------------------------------

// โญ import
import {vec, linearCombination} from './Vector.js';       // ๐Ÿ‘” Vector
// -------------------------------------------------------

// โญ MouseEvent + ext
// -------------------------------------------------------
// ๐Ÿ”ธ .pointInViewport
// ๐Ÿ”ธ .pointInPage
// ๐Ÿ”ธ .pointInScreen
// ๐Ÿ”น .pointInElement()
//
Object.defineProperties(MouseEvent.prototype, {
    
    // ๐Ÿ”ธ .pointInViewport
    pointInViewport: {
        get() {
            return vec(this.clientX, this.clientY);
        },
    },

    // ๐Ÿ”ธ .pointInPage
    pointInPage: {
        get() {
            return vec(this.pageX, this.pageY);
        },
    },

    // ๐Ÿ”ธ .pointInScreen
    pointInScreen: {
        get() {
            return vec(this.screenX, this.screenY);
        },
    },

    // ๐Ÿ”น .pointInElement()
    // - relative to element's "padding box" origin
    pointInElement: {
        value: function(elem = this.target) {
            const a = this.pointInViewport;
            const b = elem.boundingBox.origin;
            const c = elem.paddingBox.origin;
            // v = a - (b + c)
            return linearCombination([1, -1, -1], [a, b, c]);
        },
    },
    
});

// โญ export
export {};        // ES module

Last updated