<commit_before>import Class from 'lowclass'
import {CSS3DRendererNested} from '../lib/three/CSS3DRendererNested'

const sceneStates = new WeakMap

const CSS3DRendererThree = Class('CSS3DRendererThree', { // TODO rename
    initialize(scene) {
        let sceneState = sceneStates.has(scene)

        if (sceneState) sceneState = sceneStates.get(scene)
        else sceneStates.set(scene, sceneState = {
            renderer: new CSS3DRendererNested,
        })

        const { renderer } = sceneState

        this.updateResolution(scene)

        sceneState.sizeChangeHandler = () => this.updateResolution(scene)
        scene.on('sizechange', sceneState.sizeChangeHandler)

        scene._cssLayer.appendChild( renderer.domElement )
    },

    uninitialize(scene) {
        const sceneState = sceneStates.get(scene)

        if (!sceneState) return

        scene.off('sizechange', sceneState.sizeChangeHandler)
        scene._cssLayer.removeChild( sceneState.renderer.domElement )
        sceneState.renderer = null
        sceneState.sizeChangeHandler = null

        sceneStates.delete(scene)
    },

    drawScene(scene) {
        const {renderer} = sceneStates.get(scene)

        renderer.render(scene.threeCSS, scene.threeCamera)
    },

    updateResolution(scene) {
        const state = sceneStates.get(scene)

        scene._updateCameraAspect()
        scene._updateCameraPerspective()
        scene._updateCameraProjection()

        const { x, y } = scene.calculatedSize
        state.renderer.setSize( x, y )

        scene._needsToBeRendered()
    },

    requestFrame( scene, fn ) {
        requestAnimationFrame(fn)
    },

})

let instance = null

export
function getCSS3DRendererThree(scene) {
    if (instance) return instance
    else return instance = new CSS3DRendererThree
}

export
function destroyCSS3DRendererThree() {
    instance = null
}
<commit_msg>CSSRendererThree.initialize: no-op if already initialized<commit_after>import Class from 'lowclass'
import {CSS3DRendererNested} from '../lib/three/CSS3DRendererNested'

const sceneStates = new WeakMap

const CSS3DRendererThree = Class('CSS3DRendererThree', { // TODO rename
    initialize(scene) {
        let sceneState = sceneStates.get(scene)

        if (sceneState) return

        sceneStates.set(scene, sceneState = {
            renderer: new CSS3DRendererNested,
        })

        const { renderer } = sceneState

        this.updateResolution(scene)

        sceneState.sizeChangeHandler = () => this.updateResolution(scene)
        scene.on('sizechange', sceneState.sizeChangeHandler)

        scene._cssLayer.appendChild( renderer.domElement )
    },

    uninitialize(scene) {
        const sceneState = sceneStates.get(scene)

        if (!sceneState) return

        scene.off('sizechange', sceneState.sizeChangeHandler)
        scene._cssLayer.removeChild( sceneState.renderer.domElement )
        sceneState.renderer = null
        sceneState.sizeChangeHandler = null

        sceneStates.delete(scene)
    },

    drawScene(scene) {
        const {renderer} = sceneStates.get(scene)

        renderer.render(scene.threeCSS, scene.threeCamera)
    },

    updateResolution(scene) {
        const state = sceneStates.get(scene)

        scene._updateCameraAspect()
        scene._updateCameraPerspective()
        scene._updateCameraProjection()

        const { x, y } = scene.calculatedSize
        state.renderer.setSize( x, y )

        scene._needsToBeRendered()
    },

    requestFrame( scene, fn ) {
        requestAnimationFrame(fn)
    },

})

let instance = null

export
function getCSS3DRendererThree(scene) {
    if (instance) return instance
    else return instance = new CSS3DRendererThree
}

export
function destroyCSS3DRendererThree() {
    instance = null
}

{'fraction_non_alphanumeric': 0.09336154456492991, 'fraction_numerical': 0.004231684739486909, 'mean_word_length': 2.9151138716356106, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3078761', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1047, 'n_words': 206}