import _ from 'lodash';
import '../../../../assert/js/assert.js';
import '../../../../globals.js';
// Copyright 2023-2024, University of Colorado Boulder
/**
 * Mixin for RichText elements in the hierarchy that should be pooled with a clean() method.
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 */
import Matrix3 from '../../../../dot/js/Matrix3.js';
import inheritance from '../../../../phet-core/js/inheritance.js';
import memoize from '../../../../phet-core/js/memoize.js';
import { Node, scenery } from '../../imports.js';
const RichTextCleanable = memoize((type) => {
    assert && assert(_.includes(inheritance(type), Node), 'Only Node subtypes should mix Paintable');
    return class RichTextCleanableMixin extends type {
        get isCleanable() {
            return true;
        }
        /**
         * Releases references
         */
        clean() {
            const thisNode = this;
            // Remove all children (and recursively clean)
            for (let i = thisNode._children.length - 1; i >= 0; i--) {
                const child = thisNode._children[i];
                if (child.isCleanable) {
                    thisNode.removeChild(child);
                    child.clean();
                }
            }
            thisNode.matrix = Matrix3.IDENTITY;
            thisNode.freeToPool();
        }
    };
});
scenery.register('RichTextCleanable', RichTextCleanable);
export default RichTextCleanable;
//# sourceMappingURL=RichTextCleanable.js.map