import _ from 'lodash';
import '../../../../assert/js/assert.js';
import '../../../../globals.js';
// Copyright 2023-2024, University of Colorado Boulder
/**
 * Utilities and globals to support RichText
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 */
import { scenery, Text } from '../../imports.js';
export const isHimalayaElementNode = (node) => node.type.toLowerCase() === 'element';
export const isHimalayaTextNode = (node) => node.type.toLowerCase() === 'text';
const RichTextUtils = {
    // We need to do some font-size tests, so we have a Text for that.
    scratchText: new Text(''),
    // Get the attribute value from an element. Return null if that attribute isn't on the element.
    himalayaGetAttribute(attribute, element) {
        if (!element) {
            return null;
        }
        const attributeObject = _.find(element.attributes, x => x.key === attribute);
        if (!attributeObject) {
            return null;
        }
        return attributeObject.value || null;
    },
    // Turn a string of style like "font-sie:6; font-weight:6; favorite-number:6" into a may of style key/values (trimmed of whitespace)
    himalayaStyleStringToMap(styleString) {
        const styleElements = styleString.split(';');
        const styleMap = {};
        styleElements.forEach(styleKeyValue => {
            if (styleKeyValue.length > 0) {
                const keyValueTuple = styleKeyValue.split(':');
                assert && assert(keyValueTuple.length === 2, 'too many colons');
                styleMap[keyValueTuple[0].trim()] = keyValueTuple[1].trim();
            }
        });
        return styleMap;
    }
};
export default RichTextUtils;
scenery.register('RichTextUtils', RichTextUtils);
//# sourceMappingURL=RichTextUtils.js.map