7
7
*/
8
8
9
9
import { direction } from 'direction'
10
- import { isElement } from 'hast-util-is-element'
11
10
import { toString } from 'hast-util-to-string'
12
11
import { svg } from 'property-information'
13
12
import { visit , EXIT , SKIP } from 'unist-util-visit'
14
- import { element } from './util.js'
15
13
16
14
/**
17
15
* Enter a node.
@@ -36,7 +34,7 @@ export function enterState(state, node) {
36
34
/** @type {Direction | undefined } */
37
35
let dirInferred
38
36
39
- if ( element ( node ) && node . properties ) {
37
+ if ( node . type === 'element' && node . properties ) {
40
38
const lang = node . properties . xmlLang || node . properties . lang
41
39
const type = node . properties . type || 'text'
42
40
const dir = dirProperty ( node )
@@ -50,7 +48,7 @@ export function enterState(state, node) {
50
48
state . editableOrEditingHost = true
51
49
}
52
50
53
- if ( isElement ( node , 'svg' ) ) {
51
+ if ( node . tagName === 'svg' ) {
54
52
state . schema = svg
55
53
}
56
54
@@ -62,25 +60,24 @@ export function enterState(state, node) {
62
60
// Explicit `[dir=ltr]`.
63
61
dir === 'ltr' ||
64
62
// HTML with an invalid or no `[dir]`.
65
- ( dir !== 'auto' && isElement ( node , 'html' ) ) ||
63
+ ( dir !== 'auto' && node . tagName === 'html' ) ||
66
64
// `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' )
68
66
) {
69
67
dirInferred = 'ltr'
70
68
// `[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' ) {
73
71
// Check contents of `<textarea>`.
74
72
dirInferred = dirBidi ( toString ( node ) )
75
73
} else if (
76
- isElement ( node , 'input' ) &&
74
+ node . tagName === 'input' &&
77
75
( type === 'email' ||
78
76
type === 'search' ||
79
77
type === 'tel' ||
80
78
type === 'text' )
81
79
) {
82
80
// Check value of `<input>`.
83
- // @ts -expect-error something is `never` in types but this is needed.
84
81
dirInferred = node . properties . value
85
82
? // @ts -expect-error Assume string
86
83
dirBidi ( node . properties . value )
@@ -119,7 +116,11 @@ export function enterState(state, node) {
119
116
120
117
if (
121
118
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' ||
123
124
dirProperty ( child ) )
124
125
) {
125
126
return SKIP
@@ -142,7 +143,9 @@ function dirBidi(value) {
142
143
*/
143
144
function dirProperty ( node ) {
144
145
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'
146
149
? node . properties . dir . toLowerCase ( )
147
150
: undefined
148
151
0 commit comments