11import { arrayFrom , arrayConcat } from '../collection.mjs' ;
22
33export default ( apiDom ) => {
4+ // @remote -dom/polyfill does not define these constants
5+ // so we define them here manually
6+ // other dom implementations for the server could have the same constraint
7+ const
8+ ELEMENT_NODE = 1 ,
9+ ATTRIBUTE_NODE = 2 ,
10+ TEXT_NODE = 3 ,
11+ CDATA_SECTION_NODE = 4 ,
12+ PROCESSING_INSTRUCTION_NODE = 7 ,
13+ COMMENT_NODE = 8 ,
14+ DOCUMENT_NODE = 9 ,
15+ DOCUMENT_TYPE_NODE = 10 ,
16+ DOCUMENT_FRAGMENT_NODE = 11 ,
17+ ENTITY_REFERENCE_NODE = 5 ,
18+ ENTITY_NODE = 6 ,
19+ NOTATION_NODE = 12 ;
420 const child = ( el , child ) => void el . appendChild ( child ) ;
521 const childCount = ( el ) => el . childNodes . length ;
622 const childIndexGet = ( el , index ) => el . childNodes [ index ] ;
@@ -22,16 +38,16 @@ export default (apiDom) => {
2238 }
2339 }
2440 const textNode = ( text ) => apiDom . createTextNode ( text ) ;
25- const isFragment = ( el ) => el . nodeType === apiDom . DOCUMENT_FRAGMENT_NODE ;
26- const isComment = ( el ) => el . nodeType === apiDom . COMMENT_NODE ;
41+ const isFragment = ( el ) => el . nodeType === DOCUMENT_FRAGMENT_NODE ;
42+ const isComment = ( el ) => el . nodeType === COMMENT_NODE ;
2743 const isChildren = ( ch ) => ch && ch . constructor === apiDom . childNodes . constructor ;
2844 // const splice = Array.prototype.splice;
2945 return {
30- isText : ( el ) => el . nodeType === apiDom . TEXT_NODE ,
46+ isText : ( el ) => el . nodeType === TEXT_NODE ,
3147 isFragment,
3248 isComment,
33- isDeclaration : ( el ) => el . nodeType === apiDom . NOTATION_NODE ,
34- isInstruction : ( el ) => el . nodeType === apiDom . PROCESSING_INSTRUCTION_NODE ,
49+ isDeclaration : ( el ) => el . nodeType === NOTATION_NODE ,
50+ isInstruction : ( el ) => el . nodeType === PROCESSING_INSTRUCTION_NODE ,
3551 isChildren,
3652 initRoot : ( ) => apiDom . createDocumentFragment ( ) ,
3753 initName : ( name ) => apiDom . createElement ( name ) ,
@@ -50,7 +66,7 @@ export default (apiDom) => {
5066 } ;
5167 var count = list && list . length || 0 ;
5268 for ( var i = 0 ; i < count ; i ++ ) {
53- var a = list [ i ] ;
69+ var a = list [ i ] || list . item ( i ) ;
5470 var ret = handler . call ( ctx , a . name , a . value , a , i ) ;
5571 if ( ret & ctx . _remove ) el . removeAttribute ( a . name ) ;
5672 if ( ret & ctx . _break ) break ;
0 commit comments