77 */
88
99import { direction } from 'direction'
10- import { isElement } from 'hast-util-is-element'
1110import { toString } from 'hast-util-to-string'
1211import { svg } from 'property-information'
1312import { visit , EXIT , SKIP } from 'unist-util-visit'
14- import { element } from './util.js'
1513
1614/**
1715 * Enter a node.
@@ -36,7 +34,7 @@ export function enterState(state, node) {
3634 /** @type {Direction | undefined } */
3735 let dirInferred
3836
39- if ( element ( node ) && node . properties ) {
37+ if ( node . type === 'element' && node . properties ) {
4038 const lang = node . properties . xmlLang || node . properties . lang
4139 const type = node . properties . type || 'text'
4240 const dir = dirProperty ( node )
@@ -50,7 +48,7 @@ export function enterState(state, node) {
5048 state . editableOrEditingHost = true
5149 }
5250
53- if ( isElement ( node , 'svg' ) ) {
51+ if ( node . tagName === 'svg' ) {
5452 state . schema = svg
5553 }
5654
@@ -62,25 +60,24 @@ export function enterState(state, node) {
6260 // Explicit `[dir=ltr]`.
6361 dir === 'ltr' ||
6462 // HTML with an invalid or no `[dir]`.
65- ( dir !== 'auto' && isElement ( node , 'html' ) ) ||
63+ ( dir !== 'auto' && node . tagName === 'html' ) ||
6664 // `input[type=tel]` with an invalid or no `[dir]`.
67- ( dir !== 'auto' && isElement ( node , 'input' ) && type === 'tel' )
65+ ( dir !== 'auto' && node . tagName === 'input' && type === 'tel' )
6866 ) {
6967 dirInferred = 'ltr'
7068 // `[dir=auto]` or `bdi` with an invalid or no `[dir]`.
71- } else if ( dir === 'auto' || isElement ( node , 'bdi' ) ) {
72- if ( isElement ( node , 'textarea' ) ) {
69+ } else if ( dir === 'auto' || node . tagName === 'bdi' ) {
70+ if ( node . tagName === 'textarea' ) {
7371 // Check contents of `<textarea>`.
7472 dirInferred = dirBidi ( toString ( node ) )
7573 } else if (
76- isElement ( node , 'input' ) &&
74+ node . tagName === 'input' &&
7775 ( type === 'email' ||
7876 type === 'search' ||
7977 type === 'tel' ||
8078 type === 'text' )
8179 ) {
8280 // Check value of `<input>`.
83- // @ts -expect-error something is `never` in types but this is needed.
8481 dirInferred = node . properties . value
8582 ? // @ts -expect-error Assume string
8683 dirBidi ( node . properties . value )
@@ -119,7 +116,11 @@ export function enterState(state, node) {
119116
120117 if (
121118 child !== node &&
122- ( isElement ( child , [ 'bdi' , 'script' , 'style' , 'textare' ] ) ||
119+ child . type === 'element' &&
120+ ( child . tagName === 'bdi' ||
121+ child . tagName === 'script' ||
122+ child . tagName === 'style' ||
123+ child . tagName === 'textare' ||
123124 dirProperty ( child ) )
124125 ) {
125126 return SKIP
@@ -142,7 +143,9 @@ function dirBidi(value) {
142143 */
143144function dirProperty ( node ) {
144145 const value =
145- element ( node ) && node . properties && typeof node . properties . dir === 'string'
146+ node . type === 'element' &&
147+ node . properties &&
148+ typeof node . properties . dir === 'string'
146149 ? node . properties . dir . toLowerCase ( )
147150 : undefined
148151
0 commit comments