<commit_before>import Class from 'lowclass'
import './Camera'

// fallback to experimental CSS transform if browser doesn't have it (fix for Safari 9)
if (typeof document.createElement('div').style.transform == 'undefined') {
    if ( typeof CSSStyleDeclaration !== 'undefined' ) { // doesn't exist in Jest+@skatejs/ssr environment
        Object.defineProperty(CSSStyleDeclaration.prototype, 'transform', {
            set(value) {
                this.webkitTransform = value
            },
            get() {
                return this.webkitTransform
            },
            enumerable: true,
        })
    }
}

/**
 * Manages a DOM element. Exposes a set of recommended APIs for working with
 * DOM efficiently. Currently doesn't do much yet...
 */
const ElementOperations = Class('ElementOperations', ({ Private }) => ({

    constructor(element: HTMLElement) {
        Private(this).__element = element
    },

    connectChildElement(child) {
        if (

            // When using the imperative API, this statement is
            // true, so the DOM elements need to be connected.
            !child.parentNode

            // This condition is irrelevant when strictly using the
            // imperative API. However, it is possible that when
            // using the HTML API that the HTML-API node can be placed
            // somewhere that isn't another HTML-API node, and the
            // imperative Node can be gotten and used to add the
            // node to another imperative Node. In this case, the
            // HTML-API node will be added to the proper HTMLparent.
            || (child.parentElement &&
                child.parentElement !== Private(this).__element)

            // When an HTML-API node is already child of the
            // relevant parent, or it is child of a shadow root of
            // the relevant parent, there there's nothing to do,
            // everything is already as expected, so the following
            // conditional body is skipped.
        ) {
            Private(this).__add(child)
        }
    },

    disconnectChildElement(child) {
        // If DeclarativeBase#remove was called first, we don't need to
        // call this again.
        if (!child.parentNode) return

        Private(this).__remove(child)
    },

    applyImperativeNodeProperties() {
        if (!Private(this).__shouldRender) return

        Private(this).__applyOpacity()
        Private(this).__applySize()
    },

    set shouldRender(shouldRender: boolean) {
        Private(this).__shouldRender = shouldRender
        requestAnimationFrame(() => {
            Private(this).__applyStyle('display', shouldRender ? 'block' : 'none')
        })
    },
    get shouldRender(): boolean {
        return Private(this).__shouldRender
    },

    private: {
        __element: undefined! as HTMLElement,
        __shouldRender: false,

        __add(child) {
            Private(this).__element.appendChild(child)
        },

        __remove(child) {
            // This conditional check is needed incase the element was already
            // removed from the HTML-API side.
            if (child.parentNode === Private(this).__element)
                Private(this).__element.removeChild(child)
        },

        __applySize() {
            const {x,y} = (Private(this).__element as any).calculatedSize // TODO ImperativeBase typing

            Private(this).__applyStyle('width', `${x}px`)
            Private(this).__applyStyle('height', `${y}px`)

            // NOTE: we ignore the Z axis on elements, since they are flat.
        },

        __applyOpacity() {
            Private(this).__applyStyle('opacity', (Private(this).__element as any).opacity) // TODO ImperativeBase typing
        },

        /**
         * Apply a style property to the element.
         *
         * @param  {string} property The CSS property we will a apply.
         * @param  {string} value    The value the CSS property wil have.
         */<commit_msg>a few more typings for ElementOperations<commit_after>import Class from 'lowclass'
import './Camera'

// fallback to experimental CSS transform if browser doesn't have it (fix for Safari 9)
if (typeof document.createElement('div').style.transform == 'undefined') {
    if ( typeof CSSStyleDeclaration !== 'undefined' ) { // doesn't exist in Jest+@skatejs/ssr environment
        Object.defineProperty(CSSStyleDeclaration.prototype, 'transform', {
            set(value) {
                this.webkitTransform = value
            },
            get() {
                return this.webkitTransform
            },
            enumerable: true,
        })
    }
}

/**
 * Manages a DOM element. Exposes a set of recommended APIs for working with
 * DOM efficiently. Currently doesn't do much yet...
 */
const ElementOperations = Class('ElementOperations', ({ Private }) => ({

    constructor(element: HTMLElement) {
        Private(this).__element = element
    },

    connectChildElement(child: HTMLElement) {
        if (

            // When using the imperative API, this statement is
            // true, so the DOM elements need to be connected.
            !child.parentNode

            // This condition is irrelevant when strictly using the
            // imperative API. However, it is possible that when
            // using the HTML API that the HTML-API node can be placed
            // somewhere that isn't another HTML-API node, and the
            // imperative Node can be gotten and used to add the
            // node to another imperative Node. In this case, the
            // HTML-API node will be added to the proper HTMLparent.
            || (child.parentElement &&
                child.parentElement !== Private(this).__element)

            // When an HTML-API node is already child of the
            // relevant parent, or it is child of a shadow root of
            // the relevant parent, there there's nothing to do,
            // everything is already as expected, so the following
            // conditional body is skipped.
        ) {
            Private(this).__add(child)
        }
    },

    disconnectChildElement(child: HTMLElement) {
        // If DeclarativeBase#remove was called first, we don't need to
        // call this again.
        if (!child.parentNode) return

        Private(this).__remove(child)
    },

    applyImperativeNodeProperties() {
        if (!Private(this).__shouldRender) return

        Private(this).__applyOpacity()
        Private(this).__applySize()
    },

    set shouldRender(shouldRender: boolean) {
        Private(this).__shouldRender = shouldRender
        requestAnimationFrame(() => {
            Private(this).__applyStyle('display', shouldRender ? 'block' : 'none')
        })
    },
    get shouldRender(): boolean {
        return Private(this).__shouldRender
    },

    private: {
        __element: undefined! as HTMLElement,
        __shouldRender: false,

        __add(child: HTMLElement) {
            Private(this).__element.appendChild(child)
        },

        __remove(child: HTMLElement) {
            // This conditional check is needed incase the element was already
            // removed from the HTML-API side.
            if (child.parentNode === Private(this).__element)
                Private(this).__element.removeChild(child)
        },

        __applySize() {
            const {x,y} = (Private(this).__element as any).calculatedSize // TODO ImperativeBase typing

            Private(this).__applyStyle('width', `${x}px`)
            Private(this).__applyStyle('height', `${y}px`)

            // NOTE: we ignore the Z axis on elements, since they are flat.
        },

        __applyOpacity() {
            Private(this).__applyStyle('opacity', (Private(this).__element as any).opacity) // TODO ImperativeBase typing
        },

        /**
         * Apply a style property to the element.
         *
         * @param  {string} property The CSS property we will a apply.
         * @param  {string} value    The value the CSS property wil have.
         */
{'fraction_non_alphanumeric': 0.09904667574594528, 'fraction_numerical': 0.0002476166893648632, 'mean_word_length': 2.0322822822822824, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '5260783', 'n_tokens_mistral': 2042, 'n_tokens_neox': 1984, 'n_words': 659}