/**
 * @since Last modified: 2024-09-09 17:09:15
 * @function tplToEls
 * @description Convert the nodes string to the DOM nodes,Support tr tags.
 * @param {string} tpl  - Node strings, multiple sibling node strings.
 * @returns {HTMLElement[]} - Return a nodes array.
 * @see {@link https://codepen.io/axui/pen/eYxxavg|demo @ codepen}
 * @example
 * ax.tplToEls('<li>123</li><li>456</li>');
 * <!--return [li,li]-->
 */
'use strict';
import createEl from './createEl';
const tplToEls = (tpl) => {
    tpl = tpl.trim().replaceAll('&lt;', '<').replaceAll('&gt;', '>');
    if (!tpl)
        return [];
    let tplNode = createEl('TEMPLATE', '', tpl), clone = tplNode.content.cloneNode(true), firstEl = clone.firstElementChild, result;
    if (!firstEl)
        return [];
    if (firstEl.nodeName === 'TR') {
        let trs = [...clone.querySelectorAll('TR')], tmp = tplNode.innerHTML.split('</tr>').map(k => k.replace(/<\/?tr[^>]*>/g, ''));
        tmp.shift();
        trs.forEach((k, i) => {
            k.innerHTML = tmp[i];
        });
        result = trs;
    }
    else {
        result = [...clone.children];
    }
    return result;
};
export default tplToEls;
