src/loader/loader.js
function vertextes(parent, exist = [], item, _path) {
    return [...parent.children].reduce( (acc, node, index) => {
        if(node.tagName === "IMG") {
            //const [ name, props = {} ] = JSON.parse(node.getAttribute("m2") || "[]");
            node.setAttribute("m2", JSON.stringify([
                `*${imgcounter++}`, { resources: [ {type: "img", url: node.getAttribute("src") } ]}
            ]));
            item = [];
        }
        /*
        if(node.tagName === "link" && node.getAttribute("rel") === "stylesheet") {
            exist[1].resources.push( {type: "style", url: node.getAttribute("href") } );
            node.remove();
            return acc;
        }*/
        if(node.getAttribute("m2")) {
            const m2data = transform(node, item, _path);

            if(!m2data[1].template && exist[1].type !== "switcher") {
                const placer = document.createElement("div");
                placer.setAttribute("data-pid", m2data[1].pid );
                node.parentNode.replaceChild(placer, node);
            }
            node.remove();
            acc.push( m2data );
        }
        else {
            vertextes(node, exist, item, _path);
        }
        return acc;
    }, exist);
}
function vertextes(parent, exist = [], item, _path) {
    return [...parent.children].reduce( (acc, node, index) => {
        if(node.tagName === "IMG") {
            //const [ name, props = {} ] = JSON.parse(node.getAttribute("m2") || "[]");
            node.setAttribute("m2", JSON.stringify([
                `*${imgcounter++}`, { resources: [ {type: "img", url: node.getAttribute("src") } ]}
            ]));
            item = [];
        }
        /*
        if(node.tagName === "link" && node.getAttribute("rel") === "stylesheet") {
            exist[1].resources.push( {type: "style", url: node.getAttribute("href") } );
            node.remove();
            return acc;
        }*/
        if(node.getAttribute("m2")) {
            const m2data = transform(node, item, _path);

            if(!m2data[1].template && exist[1].type !== "switcher") {
                const placer = document.createElement("div");
                placer.setAttribute("data-pid", m2data[1].pid );
                node.parentNode.replaceChild(placer, node);
            }
            node.remove();
            acc.push( m2data );
        }
        else {
            vertextes(node, exist, item, _path);
        }
        return acc;
    }, exist);
}
function vertextes ( parent , exist = [ ] , item , _path ) { return [ ... parent . children ] . reduce ( ( acc , node , index ) => { if ( node . tagName === "IMG" ) { //const [ name, props = {} ] = JSON.parse(node.getAttribute("m2") || "[]"); node . setAttribute ( "m2" , JSON . stringify ( [ ` ${ imgcounter ++ } ` , { resources : [ { type : "img" , url : node . getAttribute ( "src" ) } ] } ] ) ) ; item = [ ] ; } /*
        if(node.tagName === "link" && node.getAttribute("rel") === "stylesheet") {
            exist[1].resources.push( {type: "style", url: node.getAttribute("href") } );
            node.remove();
            return acc;
        }*/ if ( node . getAttribute ( "m2" ) ) { const m2data = transform ( node , item , _path ) ; if ( ! m2data [ 1 ] . template && exist [ 1 ] . type !== "switcher" ) { const placer = document . createElement ( "div" ) ; placer . setAttribute ( "data-pid" , m2data [ 1 ] . pid ) ; node . parentNode . replaceChild ( placer , node ) ; } node . remove ( ) ; acc . push ( m2data ) ; } else { vertextes ( node , exist , item , _path ) ; } return acc ; } , exist ) ; }
todo need refactor
todo need refactor