/** * @typedef {import('hast').ElementContent} ElementContent * @typedef {import('hast').Nodes} Nodes * * @typedef {import('unist-util-visit').Visitor} Visitor * * @typedef {import('./index.js').Direction} Direction * @typedef {import('./index.js').State} State */ import {direction} from 'direction' import {toString} from 'hast-util-to-string' import {svg} from 'property-information' import {EXIT, SKIP, visit} from 'unist-util-visit' /** * Enter a node. * * The caller is responsible for calling the return value `exit`. * * @param {State} state * Current state. * * Will be mutated: `exit` undos the changes. * @param {Nodes} node * Node to enter. * @returns {() => undefined} * Call to exit. */ // eslint-disable-next-line complexity export function enterState(state, node) { const schema = state.schema const language = state.language const currentDirection = state.direction const editableOrEditingHost = state.editableOrEditingHost /** @type {Direction | undefined} */ let dirInferred if (node.type === 'element') { const lang = node.properties.xmlLang || node.properties.lang const type = node.properties.type || 'text' const dir = dirProperty(node) if (lang !== null && lang !== undefined) { state.language = String(lang) } if (schema && schema.space === 'html') { if (node.properties.contentEditable === 'true') { state.editableOrEditingHost = true } if (node.tagName === 'svg') { state.schema = svg } // See: . // Explicit `[dir=rtl]`. if (dir === 'rtl') { dirInferred = dir } else if ( // Explicit `[dir=ltr]`. dir === 'ltr' || // HTML with an invalid or no `[dir]`. (dir !== 'auto' && node.tagName === 'html') || // `input[type=tel]` with an invalid or no `[dir]`. (dir !== 'auto' && node.tagName === 'input' && type === 'tel') ) { dirInferred = 'ltr' // `[dir=auto]` or `bdi` with an invalid or no `[dir]`. } else if (dir === 'auto' || node.tagName === 'bdi') { if (node.tagName === 'textarea') { // Check contents of `